Opened 9 years ago

Closed 7 years ago

Last modified 7 years ago

#24646 closed Bug (fixed)

File names 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


On it says to create a file at myproject/ 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 Nick Pope, 9 years ago

I presume that you are using Python 2? Try:

from __future__ import absolute_import
import jinja2
# ...

This should probably be documented...

comment:2 by Daniel Greenfeld, 9 years ago

Probably. ;)

My entire history of documentation contributions to Django can be summed up as, "If readers copy/paste the code examples and they don't work, then the documentation is broken."

Last edited 9 years ago by Daniel Greenfeld (previous) (diff)

comment:3 by Aymeric Augustin, 9 years ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:5 by Tim Graham, 9 years ago

Has patch: set


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/`` with this content::
+    from __future__ import absolute_import  # Python 2 only
     from import staticfiles_storage
     from django.core.urlresolvers import reverse

comment:6 by Simon Charette, 9 years ago

Triage Stage: AcceptedReady for checkin

comment:7 by Aymeric Augustin, 9 years ago

Yes, you can ship that. Thanks!

comment:8 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In d974c89:

Fixed #24646 -- Fixed jinja2 example on Python 2.

comment:9 by Tim Graham <timograham@…>, 9 years ago

In 9e5e491:

[1.8.x] Fixed #24646 -- Fixed jinja2 example on Python 2.

Backport of d974c89ebb8a59d91f664035d98d42dbb5cdd592 from master

comment:10 by taigit, 7 years ago

Resolution: fixed
Status: closednew

The previous fix still has the same problem and causes a django error.

A fix that will get rid of the problem:
change: myproject/
to myproject/

in the documentation.

comment:11 by taigit, 7 years ago

Easy pickings: set

comment:12 by Tim Graham, 7 years ago

Resolution: fixed
Status: newclosed

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 Aymeric Augustin, 7 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.

Note: See TracTickets for help on using tickets.
Back to Top