django-views

Use `With` Tag to invert a boolean in Django Template?

ぐ巨炮叔叔 提交于 2020-01-16 03:28:08
问题 I want to pass a value to an include tag that is the OPPOSITE of a variable passed in. This is what I tried (basically): {% with s_options as not disp %} {% include "e.html" with show_options=s_options only %} {% endwith %} Is there any way to do what I want? 回答1: Not sure if this is the best solution, but I just made a new filter: from django import template register = template.Library() @register.filter(name="not_value") def not_value(true_value): return not true_value And then did: {% load

Django FormView and pagination

你说的曾经没有我的故事 提交于 2020-01-16 01:04:46
问题 I am using django's FormView to return set of objects if form is valid. My view function is as such: class IdeaView(FormView): template_name = 'contributor/browse_photo.html' def get_form_class(self): return ContributorSearchForm def form_valid(self, form): cleaned_data = form.cleaned_data filter_dict = {} for key, value in cleaned_data.iteritems(): if key == 'colour' and cleaned_data['colour']: filter_dict['colour_tag1'] = cleaned_data['colour'] if key == 'style' and cleaned_data['style']:

TypeError at /confirmemail/amlqctnhel/confirmemail() takes exactly 2 arguments (1 given), why?

假如想象 提交于 2020-01-15 11:08:29
问题 Error: TypeError at /confirmemail/amlqctnhel/ confirmemail() takes exactly 2 arguments (1 given) Request Method: GET Request URL: http://127.0.0.1:8000/confirmemail/amlqctnhel/ Django Version: 1.3.1 Exception Type: TypeError Exception Value: confirmemail() takes exactly 2 arguments (1 given) Exception Location: /usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py in get_response, line 111 Python Executable: /usr/bin/python Python Version: 2.6.6 Python Path: ['/home/user1

django smart selects on Django version 3.0.1 - error ImportError: cannot import name 'six' from 'django.utils'

旧城冷巷雨未停 提交于 2020-01-15 01:48:47
问题 Installed django-smart-selects (pip install django-smart-selects) and is not working on django version 3.0.1 I configured using the official installation guide. enter code here $ python manage.py runserver Watching for file changes with StatReloader Exception in thread django-main-thread: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self.

django smart selects on Django version 3.0.1 - error ImportError: cannot import name 'six' from 'django.utils'

ぃ、小莉子 提交于 2020-01-15 01:48:07
问题 Installed django-smart-selects (pip install django-smart-selects) and is not working on django version 3.0.1 I configured using the official installation guide. enter code here $ python manage.py runserver Watching for file changes with StatReloader Exception in thread django-main-thread: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self.

Django 2.2 breaks previously working views/urls

别等时光非礼了梦想. 提交于 2020-01-14 09:47:19
问题 Decided to take out Django 2.2 for a spin (project is currently running 2.1.8) and now I can't even get the server to start. I have been maintaining this project for nearly two years and this should be a minor update. The error seems to be related to my views, but I can't find anything in the release notes that has meaningfully changed between 2.1.8 and 2.2. I suspect it may be due to my rather non-standard view system. Instead of a single file called views.py , I use a folder of view files

Auto Generated Slugs in Django Admin

血红的双手。 提交于 2020-01-14 05:57:09
问题 I have an app that will one day allow front-end crud, which will create the slug with slugify . Right now though, all the object creation is being done in the admin area and I was wondering if there is a way to auto generate slugs while creating and saving an object from within admin? Here is the method for slugify for the front-end; not sure if its even relevant. Thank you. def create_slug(instance, new_slug=None): slug = slugify(instance.title) if new_slug is not None: slug = new_slug qs =

django render_to_response

橙三吉。 提交于 2020-01-14 03:05:15
问题 I'm putting ...}, context_instance=RequestContext(request)) at the end of all my render_to_response 's. I'm sure this is not right. Can anyone tell me when I should be using these? 回答1: You are doing it "right". This means that all of the Context Processors will run on this view, and you will have access to all of the juicy bits in your template. The other way to do this is to use direct_to_template , which saves you having to instantiate a RequestContext object, but has the same outcomes.

How to add custom permission in viewset

ⅰ亾dé卋堺 提交于 2020-01-13 19:16:09
问题 How to add custom permission in viewset in django rest framework other than the default permission while creating a module? I have a permission "fix_an_appointment". In the below viewset, how to include this permission? Those who have this permission has only able to create. My views.py file: class settingsViewSet(viewsets.ModelViewSet): serializer_class = SettingsSerializer queryset = Setting.objects.all() Can anyone help? 回答1: simply create a custom permission class class

The QuerySet value for an exact lookup must be limited to one result using slicing-Django

浪子不回头ぞ 提交于 2020-01-13 18:19:10
问题 I'm building a news website.While I tried to get the list of relative news which have the same tags.The error said: The QuerySet value for an exact lookup must be limited to one result using slicing-Django. I have two models News and Tag,Tag is a many to many foreign key of News. News model: class News(models.Model): tag = models.ManyToManyField(Tag, blank=True, verbose_name='tag') Tag model: class Tag(models.Model): name = models.CharField(max_length=40) View: def newsDetailView(request,