django-templates

NoReverseMatch with {% url … %} and keyword args

醉酒当歌 提交于 2019-12-02 01:30:28
问题 I'm having a problem with this error: Caught NoReverseMatch while rendering: Reverse for ''pennies.views.seed_preview'' with arguments '()' and keyword arguments '{'sa': 1724158887L, 'sh': 31L}' not found. which is produced by this bit of template: <a href="{% url 'pennies.views.seed_preview' sh=seed.id sa=seed.salt %}"> Preview</a> and this bit of url.py url(r'^seedpreview/sh=(?P<shareable_id>\d+)/sa=(?P<salt>\d+)$', \ 'pennies.views.seed_preview'), and this function signature def seed

How to iterate a queryset list in a django template

扶醉桌前 提交于 2019-12-02 01:18:56
Is there a way to iterate this list of querysets in the template? [<Director: Roman Polanski>, <Director: Alfred Hitchcock>, <Director: Steven Spielberg>, <Director: David Lynch>] I tried using a list syntax, but the django template language doesn't seem to accept lists, also. Thank you all. Django's template language does of course accept lists! Here is what the code in your template should look like: {% for director in director_list %} {{ director }} {% endfor %} By the way: What you're having here is a queryset (that gets evaluated to a list), not a list of querysets. 来源: https:/

Python/Django is importing the wrong module (relative when it should be absolute)

佐手、 提交于 2019-12-02 01:00:41
I'm using Django 1.2 pre-alpha and Python 2.4. Yeah, I know, but I'm stuck with it. We can't upgrade at the moment and I doubt that's the answer anyway. I've got two template tag libraries, foo and bar . However, foo is also the name of a top-level package, and it happens to be the package of bar : foo-1.2.3/ foo/ conf/ settings.py templatetags/ bar.py bar-4.5/ somepackage/ templatetags/ foo.py The tag library bar.py contains a line like this: from foo.conf import settings ...and you would expect it to load foo-1.2.3/foo/conf/settings.py . But no: TemplateSyntaxError: 'bar' is not a valid tag

How can I get the MEDIA_URL from within a Django template?

被刻印的时光 ゝ 提交于 2019-12-02 00:05:35
问题 I'm somewhat confused as to how Django operates with static content. Essentially, in the settings.py file, we define MEDIA_URL which points to the URL to use when resolving static media such as scripts and styles, as well as MEDIA_ROOT , a reference to where things live on the filesystem. However, it doesn't seem clear how I can get access to MEDIA_URL from a template, and it's kind-of-important if I want to use Django's mechanism for loading static content at all. Essentially, I have my base

how to translate an app template [closed]

a 夏天 提交于 2019-12-01 23:46:29
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I want to use multiple language in my app and for that i have followed this doc After the creation of django.po inside locale folder, I opened that, as this files contain '#' which told you that which line you

how to translate an app template [closed]

会有一股神秘感。 提交于 2019-12-01 22:32:30
I want to use multiple language in my app and for that i have followed this doc After the creation of django.po inside locale folder, I opened that, as this files contain '#' which told you that which line you can translate. But this file only contain admin part it does not have my app templates i.e., HTML files of my app. So how I can translate those HTML files, OR what should I have to do so that django.po file can also contain my app templates. I have followed only this doc . You need to use the {% trans %} or {% blocktrans %} template tags in your html files before you run python manage.py

NoReverseMatch - Django 1.7 Beginners tutorial

末鹿安然 提交于 2019-12-01 22:15:39
问题 I am following the begginers tutorial in Django 1.7.1 and am getting this error Reverse for 'vote' with arguments '(5,)' and keyword arguments '{}' not found. 0 pattern(s) tried: [] `poll\templates\poll\detail.html, error at line 12` after a bit of research I found people asking similar question and someone suggested that they should remove the cash $ from the general url, because the urlloader just takes the empty string, while this doesn't gives me the error No Reverse Match, it messes

NoReverseMatch - Django 1.7 Beginners tutorial

荒凉一梦 提交于 2019-12-01 21:39:25
I am following the begginers tutorial in Django 1.7.1 and am getting this error Reverse for 'vote' with arguments '(5,)' and keyword arguments '{}' not found. 0 pattern(s) tried: [] `poll\templates\poll\detail.html, error at line 12` after a bit of research I found people asking similar question and someone suggested that they should remove the cash $ from the general url, because the urlloader just takes the empty string, while this doesn't gives me the error No Reverse Match, it messes everything else up, whenever I try to reach any other url it redirects me to the main url, while without

Django - how to get the contents of a {% block %} tag from a template

拈花ヽ惹草 提交于 2019-12-01 21:08:28
I got this far: >>> some_template = get_template_from_string( ... load_template_source( ... 'some_template.html', ... settings.TEMPLATE_DIRS)) ... >>> blocks = some_template.nodelist.get_nodes_by_type(BlockNode) >>> blocks[0] <Block Node: another_block. Contents: [<Text Node: '\nThis one is really cool'>, <Block Node: sub_block. Contents: [<Text Node: '\nI\'m a sub-block.\n\t'>]>, <Text Node: '\n'>]> >>> # Right there is when I realized this wasn't going to be fun. You see, the contents of a block are contained in block.nodelist , as opposed to just plain text. If I have a template: {% extends

Dictionary As Table In Django Template

戏子无情 提交于 2019-12-01 20:52:12
I have a dictionary: field = { u'Birthday:': [datetime.date(2012, 4, 6), datetime.date(2012, 4, 27)], u'Education': [u'A1', u'A2'], u'Job:': [u'job1', u'job2'], u'Child Sex:': [u'M', u'F'] } My template code is: <table width="100%" border="0"> <tr> {% for k, v in field.items %} <th>{{ k }}</th> {% endfor %} </tr> <tr> {% for k,v in field.items %} <td> <table width="100%" border="0"> {% for a in v %} <tr class="{% cycle 'odd' 'even' %}"><td>{{ a }}</td></tr> {% endfor %} </table> </td> {% endfor %} </tr> </table> I want to show dictionary keys as table headers and esach value as row: Birthday