django-templates

How to change Django date format to dd/ mm/ yy?

纵然是瞬间 提交于 2019-12-10 15:43:50
问题 In forms.py: class DobForm(forms.ModelForm) dob = forms.DateField(widget=forms.TextInput(attrs={'class':'datepicker'}),required=True,input_formats=['%d/%m/%Y',]) class Meta: model = Dob In my html: $(function() {$(".datepicker").datepicker({ maxDate: '0',dateFormat: 'dd-mm-yy' })});</script> Its thorwing error in the form: Enter a valid date 回答1: You need to make the formats the same for both django and jquery. Try this for the DateField (django): ...,input_formats=['%d-%m-%Y',]) and in the

Django test client Response contains empty list of templates?

落爺英雄遲暮 提交于 2019-12-10 15:36:33
问题 According to the Django testing docs, the Django client Response object contains 'templates', which is: "A list of Template instances used to render the final content, in the order they were rendered. For each template in the list, use template.name to get the template's file name, if the template was loaded from a file. (The name is a string such as 'admin/index.html'.)" However, I am getting an empty list of templates, even though I am confident that a template was rendered. from django

Multi line string in Django 'include' statement

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 15:17:12
问题 I'm trying to be DRY with my Django templates, and have some code that I mix with CSS for a simple hover-over popup. I'd like to reuse the code, but the contents of my popup will be HTML that may well span over multiple lines. Is it possible to stuff multi-line strings into a template variable? I tried doing something funky with blocks and block.super but that only seems to work when extending (not include ) Here's an example of what I'd like to do. Is it possible? index.html <body> <h2>My

Missing Django 0.96 Template documentation (used by Google AppEngine developers)

喜夏-厌秋 提交于 2019-12-10 15:13:35
问题 Django has removed their 0.96 version of the Django 0.96 Template documentation. Does anyone have a mirror (or copy of some sort) What version of Django Templates is Google AppEngine using (out of the box) 回答1: I re-generated the documentation (seriously annoying, I had to check out just the right version of the djangoproject.com repository) and futzed with them a bit. I have published them as a courtesy to other App Engine developers: django096docs.appspot.com. Enjoy. To answer your other

Conditional include tag in Django

萝らか妹 提交于 2019-12-10 15:07:30
问题 I've ran into very strange behavior of Django template system. I have a template file, namely test.html , which recursively includes itself: {% include "test.html" %} Of course, such template has no chance to be rendered, since there is no finishing condition. OK, let's try the following: {% if test_false %}{% include "test.html" %}{% endif %}, where test_false is a variable passed to template and equal to False . One expects that it just will not include anything, but it does: RuntimeError

How to properly get url for the login view in template?

烈酒焚心 提交于 2019-12-10 14:57:14
问题 I have a small problem with figuring out how {% url 'something' %} works in django templates. When I run my website in debug mode, I see this in stdout: web_1 | [21/Dec/2015 11:29:45] "GET /accounts/profile HTTP/1.1" 302 0 web_1 | /usr/local/lib/python3.5/site-packages/django/template/defaulttags.py:499: RemovedInDjango110Warning: Reversing by dotted path is deprecated (django.contrib.auth.views.login). web_1 | url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app) web_1

Django: check for value in ManyToMany field in template

梦想的初衷 提交于 2019-12-10 14:49:20
问题 I have the following model in my Django app: class Group(models.model): name=models.CharField(max_length=30) users=Models.ManyToManyField(User) In my template, I want to display each group, along with a button underneath each. If the user is already in the group, I want to display a "Leave Group" button, and if they are not already in the group, I want to display a "Join Group" button. What is the most efficient way to determine whether the currently logged in user is in each group? I would

django slice string in template

天大地大妈咪最大 提交于 2019-12-10 13:17:38
问题 index.html <td>{% if place or other_place or place_description%}{{ place}} {{ other_place}} {{place_description}}</td> This is displaying all the data in template.I want to truncate the string if it is more than length 80. Conditions are, 1.If place variable have more than 80 character,it should truncate their and need not show the other two variable like other_place and place_description. 2.If place variable and other_place variable making more than 80 character,in this case it should

django __unicode__() - how can i call this method in a template

﹥>﹥吖頭↗ 提交于 2019-12-10 13:09:59
问题 I defined a unicode () method in my Contact model. def __unicode__(self): return u'%s %s' % (self.first_name, self.last_name) Now I want to show the return value of the unicode () method in a template. But all that i try fails. {{ object.unicode }} or {{ object.unicode() }} or {{ object.__unicode__ }} or {{ object.str }} That confuses me since I have another Model level function which can be referenced to from the template without problems. This works fine: def get_id(self): return "%i" %

Django Admin: Pre-populating values from POST or GET?

允我心安 提交于 2019-12-10 12:48:02
问题 In my Django 1.2.4 site, I would like to direct the user to an admin page that is pre-filled out with some values, based on the current data they are working with. For example: {% for person in people %} <tr> <td>{{person}}</td> <td><a href='admin/foo/bar/add?name={{person}}'>Create a foo for {{person}}</td> </tr> {% endfor %} Then, when the user clicks on the link, the name field is pre-populated with the value {{person}} . Does the Django Admin interface support doing this? The Django admin