Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango Templatetags Import Error
    text
    copied!<p>I've been banging my head against this for a while, but can't seem to figure it out. I've got an app with a set of custom template tags:</p> <pre><code>from django import template from crowd.models import Payment, Project, ProjectCategory register = template.Library() @register.filter def is_customer(user, project): try: return Payment.objects.filter(user=user, project=project).count() &gt; 0 except: return False </code></pre> <p>That throws:</p> <pre><code>'project_tags' is not a valid tag library: ImportError raised loading crowd.templatetags.project_tags: No module named models </code></pre> <p>The app tree looks like:</p> <pre><code>crowd/ -- __init__.py -- models.py templatetags/ -- __init__.py -- project_tags.py </code></pre> <p>Importing from just models and crowd.models both give me the same error.</p> <p>Traceback: <a href="http://pastebin.com/6JYPT5qF" rel="nofollow">here</a></p> <h2>Update</h2> <p>I was working on something unrelated when I noticed this was broken, so I reverted to an earlier, known working version of the project. Still the same problem, so I think Daniels answer about the PYTHONPATH is correct, however, how can I repair this?</p> <pre><code>&gt;&gt;&gt; import sys &gt;&gt;&gt; sys.path ['/Users/****/Documents/dev/product/src/Product', ...] </code></pre> <p>The __init__.py's are all there all the way down, and crowd is in Product, so shouldn't it be on the path?</p> <h2>Update 2</h2> <p>I've done some investigating in the shell:</p> <pre><code>&gt;&gt;&gt; from crowd.models import * &gt;&gt;&gt; from crowd.managers import * &gt;&gt;&gt; from crowd.constants import * &gt;&gt;&gt; from crowd.templatetags import * &gt;&gt;&gt; from crowd.templatetags import project_tags Traceback (most recent call last): File "&lt;console&gt;", line 1, in &lt;module&gt; File "/Users/Murph/Documents/dev/product/src/Product/crowd/templatetags/project_tags.py", line 4, in &lt;module&gt; from crowd.forms import SearchForm File "/Users/Murph/Documents/dev/product/src/Product/crowd/forms.py", line 5, in &lt;module&gt; from crowd.models import Payment, Project, ProjectUpdate, GalleryPhoto ImportError: No module named models &gt;&gt;&gt; </code></pre> <p>Still don't know <em>why</em> specifically that's failing, especially since the blanket import works.</p> <h2>Update 3</h2> <p>Took me a while to see that the shell command was giving a more useful message than the django one, which led to this:</p> <p>Turns out it wasn't even related to project_tags directly, it just wasn't a very useful error message. The import in project_tags.py of:</p> <pre><code> from crowd.forms import SearchForm </code></pre> <p>was calling:</p> <pre><code>from crowd.models import Payment, Project, RewardLevel, ProjectUpdate, GalleryPhoto </code></pre> <p>in forms.py, which should have been:</p> <pre><code>from models import Payment, Project, RewardLevel, ProjectUpdate, GalleryPhoto </code></pre> <p>I'll add this as the answer when I can, apparently can't until 8 hours later.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload