django-templates

Django Templates First element of a List

…衆ロ難τιáo~ 提交于 2019-12-20 16:58:43
问题 I pass a dictionary to my Django Template, Dictionary & Template is like this - lists[listid] = {'name': l.listname, 'docs': l.userdocs.order_by('-id')} {% for k, v in lists.items %} <ul><li>Count: {{ v.docs.count }}, First: {{ v.docs|first }}</li></ul> {% endfor %} Now docs is a list of userdocs type. i.e. is an instance. So first filter returns me this instance. From this I need to extract it's id . How do I do that? I tried {{ v.docs|first }}.id and various other futile trials. 回答1: You

Django Templates First element of a List

大憨熊 提交于 2019-12-20 16:58:32
问题 I pass a dictionary to my Django Template, Dictionary & Template is like this - lists[listid] = {'name': l.listname, 'docs': l.userdocs.order_by('-id')} {% for k, v in lists.items %} <ul><li>Count: {{ v.docs.count }}, First: {{ v.docs|first }}</li></ul> {% endfor %} Now docs is a list of userdocs type. i.e. is an instance. So first filter returns me this instance. From this I need to extract it's id . How do I do that? I tried {{ v.docs|first }}.id and various other futile trials. 回答1: You

Django templates: overriding blocks of included children templates through an extended template

牧云@^-^@ 提交于 2019-12-20 16:17:11
问题 I'm wondering if anyone knows how to deal with the following quirky template structure: ### base.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html lang="en"> <head> <title> {% block title %} Title of the page {% endblock %} </title> </head> <body> <header> {% block header %} {% include "base/header.html" %} {% endblock header %} </header> {% block content %}{% endblock %} </body> </html> ### base/header.html <div id="menu-bar"> {% block nav %} {% include "base/nav.html" %} {%

Nested django templates

谁说我不能喝 提交于 2019-12-20 12:42:21
问题 This seems like a pretty basic thing to do but although I've been using Django for around a year, I've never run into this scenario yet. In a lot of templating/web frameworks, template inheritance works a bit differently, in that usually it behaves more like wrappers, so if you have childtemplate.html, parenttemplate.html, and grandparenttemplate.html, then the finally rendering usually looks something like: grandparent header parent header child header child content parent content parent

Django form field grouping

坚强是说给别人听的谎言 提交于 2019-12-20 12:36:10
问题 Say I have a form with 20 fields, and I want to put 10 of these fields (group1) in a particular div environment and the other 10 fields (group2) in a different div environment. Something like: <div class="class1"> {% for field in form.group1 %} {{ field.label}}: {{ field }} {% endfor %} </div> <div class="class2"> {% for field in form.group2 %} {{ field.label}}: {{ field }} {% endfor %} </div> Any ideas how I could accomplish this by iterating over the fields? More generally, I would like to

What is Django's TEMPLATE_DEBUG setting for?

时间秒杀一切 提交于 2019-12-20 12:04:08
问题 I have been trying to find information about this setting but there isn't much. Can someone explain me what is this setting about? Should I turn it off in production?... Just want to learn about it, maybe I'm missing something important in django. (I use django 1.6) 回答1: This setting helps with debugging errors/exceptions raised while rendering the templates. If it is set to True and DEBUG is True , Django would show you usual "fancy" error page with a traceback, request details and other

Custom django admin templates not working

杀马特。学长 韩版系。学妹 提交于 2019-12-20 11:54:28
问题 I've been trying to get custom templates for the admin page for Django working but have been unsuccessful. I've read the django documentation and several blogs which explain it as being such an easy step, which I assumed it was. As of right now the admin page works but my own rewrite of the CSS or templates is not working. My setup is as follows /project_folder/ manage.py settings.py urls.py __init__.py /app/ views.py models.py __init__.py /templates/ /admin/ base_site.html In the urls.py I

Calling block inside an if condition: django template

巧了我就是萌 提交于 2019-12-20 11:52:28
问题 I have been trying to call a block inside an if condition in django template. I have a base template . I have many other templates that extend the base template. I have defined a block in base template: {% block test_block %}Test{% endblock %} I then want to override this block on a certain condition in the other templates. If the condition fails, the block shouldn't get overridden. This is something what I have written: {% if test_value %}{% block test_block %}Development{% endblock %}{%

Calling block inside an if condition: django template

送分小仙女□ 提交于 2019-12-20 11:52:05
问题 I have been trying to call a block inside an if condition in django template. I have a base template . I have many other templates that extend the base template. I have defined a block in base template: {% block test_block %}Test{% endblock %} I then want to override this block on a certain condition in the other templates. If the condition fails, the block shouldn't get overridden. This is something what I have written: {% if test_value %}{% block test_block %}Development{% endblock %}{%

Updating several records at once using Django

情到浓时终转凉″ 提交于 2019-12-20 11:21:21
问题 I want to create a list of records with checkboxes on the left side....kinda like the inbox in Gmail. Then if a user selects some or all of these checkboxes, then the selected record(s) can be updated (only one field will be updated BTW), possibly by clicking a button. I'm stuck on how to do this though....ideas? Display Code {% for issue in issues %} <tr class="{% cycle 'row1' 'row2' %}"> <td><input name="" type="checkbox" value="{{ issue.id }}" /></td> <td>{{ issue.description }}</td> <td>{