django-views

django template extends not working

本小妞迷上赌 提交于 2019-11-30 23:13:21
问题 This is my base.html <!DOCTYPE html> <head> <title> My Site </title> </head> <body> <div id="wrapper"> <!-- HEADER START --> {% block nav %} {% endblock %} {% block index %} {% endblock %} </div> </body> </html> this is my nav.html {% extends "base.html" %} {% block nav %} <div id="header"> <div class="inner"> <div class="nav"> <ul> <li class="current"><a href="index.html">Home</a></li> <li><a href="about.html">About</a></li> <li><a href="blog_right.html">Blog</a></li> <li><a href="contact

'instancemethod' object has no attribute '__getitem__'

孤者浪人 提交于 2019-11-30 22:24:09
问题 I keep getting this error: TypeError: 'instancemethod' object has no attribute '__getitem__' With my particular view on a django site I am playing around with. I have no idea why but I have a feeling it might be related to the way I am retrieving a specific object from a model. The error occurs here: def myview(request): if request.method == 'POST': tel = request.POST.get['tel_number'] person = get_object_or_404(Employee,phone_number=tel) # HERE I have an Employee model with phone_number as a

Django and root processes

怎甘沉沦 提交于 2019-11-30 21:34:43
In my Django project I need to be able to check whether a host on the LAN is up using an ICMP ping. I found this SO question which answers how to ping something in Python and this SO question which links to resources explaining how to use the sodoers file. The Setting A Device model stores an IP address for a host on the LAN, and after adding a new Device instance to the DB (via a custom view, not the admin) I envisage checking to see if the device responds to a ping using an AJAX call to an API which exposes the capability. The Problem However (from the docstring of a library suggested in the

How to get information from Django_tables2 row?

泪湿孤枕 提交于 2019-11-30 21:29:56
I have declared a table and want to fetch the row's value which is checked using checkboxfield. Any help, how can i write this event in my views so that everytime I select a row and hit submit button, it returns the row's values.Code goes like this: class mytables(tables.Table): new_database = tables.CheckBoxColumn() student =tables.Column(accessor='Student') Class = tables.Column(accessor='class') And in my templates a submit button. You need to choose a suitable value for the CheckBoxColumn . Generally if you're displaying a queryset, you'll use the pk of each object for the CheckBoxColumn .

Search through multiple fields in Django

送分小仙女□ 提交于 2019-11-30 21:20:43
I'm trying to build a search system, and I want to search by multiple fields name, state, city, in my django models. I wrote the below code, yet I've been unable to figure out how to go about it. Models: class Finhall(models.Model): user=models.ForeignKey(User) name=models.CharField(max_length=250, unique=True) address=models.CharField(max_length=200) city=models.CharField(max_length=200) state=models.CharField(max_length=200) def __unicode__(self): return u'%s' % (self.name) Views.py def hup_find(request): if ('q' in request.GET) and request.GET['q'].strip(): query_string=request.GET.get('q')

django-registration, registration and login form on index page together, did I do it right?

妖精的绣舞 提交于 2019-11-30 20:48:15
问题 I'd appreciate some code review, I used django-registration app and django.contrib.auth module. What I wanted to do is have both the login and registration form on the index page, and manage it from there. What I did is I just copied code from registration.views.py and contrib.auth.views.py and banged it together. It works but I feel it's very hack-ish, non elegant, and that there is another, proper way to do it. For example I feel it might be better to call or extend view methods in

How to return multiple objects related with ForeignKey in Django

岁酱吖の 提交于 2019-11-30 20:10:10
I have the following in my models.py: class HostData(models.Model): Manager = models.ForeignKey(Managers) Host = models.CharField(max_length=50, null=True) HostStatus = models.CharField(max_length=200, null=True) Cpu = models.PositiveIntegerField(max_length=10, null=True) Disk = models.FloatField(null=True) I would like to return the query for objects related to a certain "Manager". The problem is that the user may add/delete as many managers as he wants. So my initial thought was to have in my views.py something like this: def get_data(request): for server in Managers.objects.all(): host_data

django count of foreign key model

ⅰ亾dé卋堺 提交于 2019-11-30 20:04:46
Hi i want to display count of answers to my question model my model: class Question(models.Model): text = models.TextField() title = models.CharField(max_length=200) date = models.DateTimeField(default=datetime.datetime.now) author = models.ForeignKey(CustomUser) tags = models.ManyToManyField(Tags) def __str__(self): return self.title class Answer(models.Model): text = models.TextField() date = models.DateTimeField(default=datetime.datetime.now) likes = models.IntegerField(default=0) author = models.ForeignKey(CustomUser) question = models.ForeignKey(Question) my view: def all_questions

django run another class-based view (CBV) in a CBV?

核能气质少年 提交于 2019-11-30 18:29:18
问题 so I have a CBV (A), CBV (B), and a url like regex=r'^(?P<slug>[-\w]+)/(?P<app>[-\w]+)' I want to read in the slug and app parameters with (A) and then based on those, redirect it to an appropriate CBV, possible (B). I don't want to redirect the user with HttpResponseRedirect or anything like that, but instead basically run another CBV as if it were the one being called. How do I run another CBV, like (B), directly/internally from a CBV (A)? 回答1: You can call it that way: class CBViewA(View):

Django redirect using reverse() to a URL that relies on query strings

给你一囗甜甜゛ 提交于 2019-11-30 18:21:59
I'm writing a django application with a URL like 'http://localhost/entity/id/?overlay=other_id'. Where id is the primary key of the particular entity and overlay is an optional query parameter for a second entity to be overlaid in the display. The user can only ever update an entity when viewing objects through an overlay. When POSTing to /update/id, I want to redirect back to /entity/id, but I don't want to lose my query parameter during the redirect, as the change in view would be jarring. For example, I've got the following in my url.py: ... (r'^update/(?P<id>.+)/(?P<overlay_id>.+)/$',