Opened 10 years ago
Closed 10 years ago
#25570 closed Bug (wontfix)
Using a templatetag in a Python file in a project template causes an Exception
| Reported by: | Daniel Finch | Owned by: | nobody |
|---|---|---|---|
| Component: | Utilities | Version: | 1.8 |
| Severity: | Normal | Keywords: | |
| Cc: | daniel.samuels1@… | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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.
Change History (3)
comment:1 by , 10 years ago
| Cc: | added |
|---|---|
| Component: | Uncategorized → Utilities |
| Type: | Uncategorized → Bug |
comment:2 by , 10 years ago
comment:3 by , 10 years ago
| Resolution: | → wontfix |
|---|---|
| Status: | new → closed |
The documentation 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.