django-templates

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

Syntax to supply a parameter to a custom template tag in {% if %} block

喜夏-厌秋 提交于 2020-01-15 12:30:09
问题 I have setup a custom template tag (simple_tag) (using https://stackoverflow.com/a/7716141/1369798) with a definition like this: templatetags/polls_extras.py def settings_value(name) which I am able to use in my template like this: templates/index.html {% settings_value "ALLOWED_BOOL" %} But this just inserts the text into my HTML output. What is the syntax to use my template tag with parameter in an {% if %}? I tried this but I get the error: TemplateSyntaxError at / Unused '"ALLOWED_BOOL"'

Why is Django template loop nesting my divs?

≯℡__Kan透↙ 提交于 2020-01-15 09:47:06
问题 I am using Bootstrap with Django and want the .item-container.col-md-4 to be three boxes inside a row. It should look something like this: <div class="row"> <div class="item-container col-md-4> Stuff</div> <div class="item-container col-md-4> Another Thing</div> <div class="item-container col-md-4> This Next One</div> </div> I am getting something more like this: <div class="row"> <div class="item-container col-md-4> Stuff <div class="item-container col-md-4> Another Thing</div> </div> </div>

Django custom error message

爷,独闯天下 提交于 2020-01-15 09:32:29
问题 I want to display error messages in my native language. Below pasted code from 4 different trials and none of them worked None of the methods I found were not working Django, Models & Forms: replace "This field is required" message forms.py class UserCreateForm(UserCreationForm): email = forms.EmailField(required=True, error_messages = {'required': "custom"}) first_name = forms.CharField(required=True) last_name = forms.CharField(required=True) class Meta: model = User fields = ("username",

Django custom error message

青春壹個敷衍的年華 提交于 2020-01-15 09:32:12
问题 I want to display error messages in my native language. Below pasted code from 4 different trials and none of them worked None of the methods I found were not working Django, Models & Forms: replace "This field is required" message forms.py class UserCreateForm(UserCreationForm): email = forms.EmailField(required=True, error_messages = {'required': "custom"}) first_name = forms.CharField(required=True) last_name = forms.CharField(required=True) class Meta: model = User fields = ("username",

Django custom error message

坚强是说给别人听的谎言 提交于 2020-01-15 09:32:05
问题 I want to display error messages in my native language. Below pasted code from 4 different trials and none of them worked None of the methods I found were not working Django, Models & Forms: replace "This field is required" message forms.py class UserCreateForm(UserCreationForm): email = forms.EmailField(required=True, error_messages = {'required': "custom"}) first_name = forms.CharField(required=True) last_name = forms.CharField(required=True) class Meta: model = User fields = ("username",

Django multiple annotate slows down the query

自古美人都是妖i 提交于 2020-01-15 03:59:29
问题 I have been debugging with django debug_toolbar , if I use more than one annotate in query then it takes a lot of time for Django to fetch the query results. class Project_First(models.Model): project_first_results_M2M = models.ManyToManyField(Project_First_Results) class Project_Second(models.Model): project_second_results_M2M = models.ManyToManyField(Project_Second_Results) class Project(models.Model): project_first_M2M = models.ManyToManyField(Project_First) project_second_M2M = models

Django multiple annotate slows down the query

你离开我真会死。 提交于 2020-01-15 03:59:07
问题 I have been debugging with django debug_toolbar , if I use more than one annotate in query then it takes a lot of time for Django to fetch the query results. class Project_First(models.Model): project_first_results_M2M = models.ManyToManyField(Project_First_Results) class Project_Second(models.Model): project_second_results_M2M = models.ManyToManyField(Project_Second_Results) class Project(models.Model): project_first_M2M = models.ManyToManyField(Project_First) project_second_M2M = models

Unable to provide image names dynamically to {% static " in AngularJS

六眼飞鱼酱① 提交于 2020-01-15 03:55:33
问题 <div class="container" ng-repeat="item in itemslist"> <img ng-src="{% static "img/new/item.imagename" %}" alt="" /> </div> item - > is an object, below is the object definition var firstItem = {}; firstItem.id = 0; firstItem.name = "testfirstname"; firstItem.imagename = "cart.png"; var secondItem = {}; secondItem.id = 2; secondItem.name = "testsecondname"; secondItem.imagename = "home.png"; itemslist - > [firstitem, seconditem] In the runtime, item.imagename is not getting replaced by its

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.