#24646 closed Bug (fixed)
File names jinja2.py cannot import jinja2
Reported by: | Daniel Greenfeld | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 1.8 |
Severity: | Normal | Keywords: | jinja2 |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
On https://docs.djangoproject.com/en/1.8/topics/templates/ it says to create a file at myproject/jinja2.py which includes import jinja2
, which breaks on the fact that you can't import a module into something named the same as the module.
Change History (13)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
Probably. ;)
My entire history of documentation contributions can be summed up as, "If readers copy/paste the code examples and they don't work, then the documentation is broken."
comment:3 by , 10 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Uncategorized → Bug |
comment:5 by , 10 years ago
Has patch: | set |
---|
Good?
diff --git a/docs/topics/templates.txt b/docs/topics/templates.txt index 9f0048b..d3b951a 100644 --- a/docs/topics/templates.txt +++ b/docs/topics/templates.txt @@ -415,6 +415,8 @@ APIs, you must configure them into the environment. For example, you can create ``myproject/jinja2.py`` with this content:: + from __future__ import absolute_import # Python 2 only + from django.contrib.staticfiles.storage import staticfiles_storage from django.core.urlresolvers import reverse
comment:6 by , 10 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:10 by , 8 years ago
Resolution: | fixed |
---|---|
Status: | closed → new |
The previous fix still has the same problem and causes a django error.
see: http://stackoverflow.com/questions/40873096/error-when-using-jinja2-as-django-template-engine-cannot-import-name-environme/40873097#40873097
A fix that will get rid of the problem:
change: myproject/jinja2.py
to myproject/jinja2_bridge.py
in the documentation.
comment:11 by , 8 years ago
Easy pickings: | set |
---|
comment:12 by , 8 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I can't reproduce a problem unless I remove the from __future__ import absolute_import
that the commit for this ticket added. Could you please provide a sample project that reproduces the problem? Ideally, you would use our support channnels rather than this ticket tracker. Thanks.
comment:13 by , 8 years ago
The point is almost moot as the next version of Django will drop support for Python 2, and this problem can't happen on Python 3.
I presume that you are using Python 2? Try:
This should probably be documented...