django-views

Validating a form with overloaded _init_

坚强是说给别人听的谎言 提交于 2019-12-31 05:34:30
问题 I have a form with a new init method, which allow to display various choices according to a parameter : class Isochrone_Set_Parameters(forms.Form): Grid_Choices = Grids_Selection.Grid_Choices def __init__(self, Grid_Type, *args, **kwargs): super(Isochrone_Set_Parameters, self).__init__(*args, **kwargs) if Grid_Type == Grids_Selection.Grid_Values[0]: Choices = (('0.0','0.0'),('0.1','0.1'),('0.3','0.3'),('0.5','0.5'),('0.6','0.6'),('0.7','0.7'), \ ('0.8','0.8'),('0.9','0.9'),('0.95','0.95'))

NoReverseMatch at /kitty_view Reverse for 'kitty' with arguments '(5,)' not found. 1 pattern(s) tried: ['kitty$']

天涯浪子 提交于 2019-12-31 05:31:30
问题 While rendering this kitty_view I am getting this error. Exactly the same thing I have copied from another app that is working properly. Kindly help. View.py def kitty_view(request): kitty_list = kitty.objects.all().order_by('-cretime') code1 = str(request.GET.get('Code')) name1 = str(request.GET.get('nam')) status1 = str(request.GET.get('stat')) if (name1 is not None and name1 != ''): kitty_list = kitty_list.filter(name=name1) if (code1 is not None and code1 != ''): kitty_list = kitty_list

show loading gif during long processing in django?

大憨熊 提交于 2019-12-31 05:27:08
问题 I do my project using Django 1.8 . I want put a GIF to during call key_generate function. How can I do this using Django. I refer this question to reference Link but I couldn't understand how apply it my code. This is my view function. from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User from django.shortcuts import get_object_or_404, redirect, render from django.core.exceptions import PermissionDenied from django.http import HttpResponse from

Django: Using a variable as the URL namespace?

孤街浪徒 提交于 2019-12-31 04:14:04
问题 I'm trying to create a submenu for a sports site. Each sport would need its own submenu. The problem I'm having is I need the namespace itself to be dynamic in someway. SportListView returns the sport so I can then filter the news articles by the sport. Views: class SportListView(ListView): template_name="sports/sport-home.html" context_object_name='sport_list' def get_context_data(self, **kwargs): context = super(SportListView, self).get_context_data(**kwargs) context['sport_menu'] = get

django ValueError: invalid literal for int() with base 10: ''

为君一笑 提交于 2019-12-31 03:54:13
问题 I have an issue with my site, receiving this error pretty often. It's the first time i've run into this and maybe someone can shed some light as to why? Traceback (most recent call last): File "/opt/python2.6/lib/python2.6/site-packages/django/core/handlers/base.py", line 92, in get_response response = callback(request, *callback_args, **callback_kwargs) File "/www/django_test1/fundedbyme/project/views.py", line 194, in browse items = Project.objects.filter(categories__slug=cat_name, status=

Project Matching Query Does Not Exist Error?

Deadly 提交于 2019-12-31 03:17:15
问题 This is the view: def showProject(request, project_slug): project = Project.objects.get(slug=project_slug) tickets = Ticket.objects.filter(project=project) payload = { 'project':project, 'tickets':tickets } return render(request, 'project/project.html', payload) This is the error: Traceback: File "C:\Python27\lib\site-packages\django-1.3-py2.7.egg\django\core\handlers\base.py" in get_response 111. response = callback(request, *callback_args, **callback_kwargs) File "C:\project\views.py" in

Using Django to summarize Report

≡放荡痞女 提交于 2019-12-31 03:12:21
问题 I'm trying to produce a table that will show the total maturity amounts for each financial institution that a plan has. A plan is the term I use for person. So each person can have multiple investments. I'm having trouble creating a table that will do this correctly. Currently I have a report that displays each investment sorted by Maturity Date, i.e. 2011,2012, etc. At the bottom I would like to place this summary table, but my query displays duplicates of each financial institution, due to

Filter select field in ModelForm by currently logged in user

╄→尐↘猪︶ㄣ 提交于 2019-12-30 13:36:21
问题 I'm trying to display a form (ModelForm) with a select field filtered by currently logged in user. The select field in this case contains a list of categories. I want to display only the categories which "belong" to the currently logged in user. The category field is a foreign key to the IngredienceCategory model. Here is what I've come up with so far but it's giving me an error (unexpected keyword queryset). Any ideas what I'm doing wrong? # models.py class IngredienceCategory(models.Model):

Accessing global variable in view using context processor in Django

北城以北 提交于 2019-12-30 09:32:49
问题 Assuming I have a context processor: def title(request): return {'titles': 'mytitle'} I can access this variable in template as {{ titles }} . But how can I do so in a view? def myview(request): print request.titles doesn't seem to work - 'WSGIRequest' object has no attribute 'titles' Or maybe there is a better approach (than context processors) to have global variables accessible in both views and templates? Thanks in advance. 回答1: Context processors aren't in any way global variables. They

Django raising 404 with a message

此生再无相见时 提交于 2019-12-30 08:41:45
问题 I like to raise 404 with some error message at different places in the script eg: Http404("some error msg: %s" %msg) So, in my urls.py I included: handler404 = Custom404.as_view() Can anyone please tell me how should I be handling the error in my views. I'm fairly new to Django, so an example would help a lot. Many thanks in advance. 回答1: In general, 404 error is "page not found" error - it should not have customizable messages, simply because it should be raised only when a page is not found