[Django] #25570: Using a templatetag in a Python file in a project template causes an Exception

22 views
Skip to first unread message

Django

unread,
Oct 19, 2015, 9:29:59 AM10/19/15
to django-...@googlegroups.com
#25570: Using a templatetag in a Python file in a project template causes an
Exception
-------------------------------+--------------------
Reporter: danielsamuels | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
If you have a Python file in your project template and you have a string
of code such as {{{ {% static %} }}}, startproject will throw an exception
as it tries to render the tag.

As a minimum viable test case, I put together the following repository:
https://github.com/danielsamuels/django-project-template-bug
It consists of a single {{{ __init__.py }}} with a comment inside, the
contents of the comment being {{{ {% static %} }}}. Using this as a
project template will cause the following exception to be thrown:

{{{ django-admin startproject output --template
https://github.com/danielsamuels/django-project-template-
bug/archive/master.zip }}}

{{{
Traceback (most recent call last):
File "/Users/danielsamuels/Workspace/testing/.venv/bin/django-admin",
line 11, in <module>
sys.exit(execute_from_command_line())
File "/Users/danielsamuels/Workspace/testing/.venv/lib/python2.7/site-
packages/django/core/management/__init__.py", line 351, in
execute_from_command_line
utility.execute()
File "/Users/danielsamuels/Workspace/testing/.venv/lib/python2.7/site-
packages/django/core/management/__init__.py", line 343, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/danielsamuels/Workspace/testing/.venv/lib/python2.7/site-
packages/django/core/management/base.py", line 394, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/danielsamuels/Workspace/testing/.venv/lib/python2.7/site-
packages/django/core/management/base.py", line 445, in execute
output = self.handle(*args, **options)
File "/Users/danielsamuels/Workspace/testing/.venv/lib/python2.7/site-
packages/django/core/management/commands/startproject.py", line 33, in
handle
super(Command, self).handle('project', project_name, target,
**options)
File "/Users/danielsamuels/Workspace/testing/.venv/lib/python2.7/site-
packages/django/core/management/templates.py", line 151, in handle
template = Engine().from_string(content)
File "/Users/danielsamuels/Workspace/testing/.venv/lib/python2.7/site-
packages/django/template/engine.py", line 153, in from_string
return Template(template_code, engine=self)
File "/Users/danielsamuels/Workspace/testing/.venv/lib/python2.7/site-
packages/django/template/base.py", line 190, in __init__
self.nodelist = engine.compile_string(template_string, origin)
File "/Users/danielsamuels/Workspace/testing/.venv/lib/python2.7/site-
packages/django/template/engine.py", line 261, in compile_string
return parser.parse()
File "/Users/danielsamuels/Workspace/testing/.venv/lib/python2.7/site-
packages/django/template/base.py", line 339, in parse
self.invalid_block_tag(token, command, parse_until)
File "/Users/danielsamuels/Workspace/testing/.venv/lib/python2.7/site-
packages/django/template/base.py", line 395, in invalid_block_tag
raise self.error(token, "Invalid block tag: '%s'" % command)
django.template.base.TemplateSyntaxError: Invalid block tag: 'static'
}}}

In theory, this project template _should_ work, given that the templatetag
is just a comment within the project.

--
Ticket URL: <https://code.djangoproject.com/ticket/25570>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 19, 2015, 9:30:25 AM10/19/15
to django-...@googlegroups.com
#25570: Using a templatetag in a Python file in a project template causes an
Exception
-------------------------------+--------------------------------------
Reporter: danielsamuels | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by danielsamuels):

* cc: daniel.samuels1@… (added)
* needs_better_patch: => 0
* component: Uncategorized => Utilities
* needs_tests: => 0
* needs_docs: => 0
* type: Uncategorized => Bug


--
Ticket URL: <https://code.djangoproject.com/ticket/25570#comment:1>

Django

unread,
Oct 19, 2015, 10:08:49 AM10/19/15
to django-...@googlegroups.com
#25570: Using a templatetag in a Python file in a project template causes an
Exception
-------------------------------+--------------------------------------
Reporter: danielsamuels | Owner: nobody

Type: Bug | Status: new
Component: Utilities | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by timgraham):

The documentation [https://docs.djangoproject.com/en/1.8/ref/django-admin
/#render-warning warns about this]. I'm not sure it can/should be fixed as
it seems to me we cannot treat some part of the file as a template but not
others.

--
Ticket URL: <https://code.djangoproject.com/ticket/25570#comment:2>

Django

unread,
Oct 21, 2015, 9:23:52 AM10/21/15
to django-...@googlegroups.com
#25570: Using a templatetag in a Python file in a project template causes an
Exception
-------------------------------+--------------------------------------
Reporter: danielsamuels | Owner: nobody
Type: Bug | Status: closed
Component: Utilities | Version: 1.8
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => wontfix


--
Ticket URL: <https://code.djangoproject.com/ticket/25570#comment:3>

Reply all
Reply to author
Forward
0 new messages