Reputation: 10774
I am having trouble in getting my site to recognise custom template tags. I have the following dir structure:
Then I have added this to the INSTALLED_APPS:
INSTALLED_APPS = (
# 'django.contrib.auth',
'django.contrib.contenttypes',
# 'django.contrib.sessions',
'django.contrib.sites',
'project_name'
)
I then reference this inside the template like this:
{% load getattribute %}
{% for header in headers %}
<td>{{ obj|getattribute:header }}</td>
{% endfor %}
The error which I get is as follows:
Could not import controllers.EventController. Error was: No module named project_name
Any help would be appreciated for this:
TIA
Andrew
UPDATE:
The site works but I cannot get the template tags to work. If I remove the project_name from the installed_apps I get the following error:
Exception Value: 'getattribute' is not a valid tag library: Could not load template library from django.templatetags.getattribute, No module named getattribute
Upvotes: 1
Views: 1310
Reputation: 31582
The error is becaus you have wrong your folder's structure, i think you must read the docs, this tutorial (part1) explains the right structure:
You have a project that isn't same thing that app:
And in your INSTALLED_APPS
:
INSTALLED_APPS = (
# 'django.contrib.auth',
'django.contrib.contenttypes',
# 'django.contrib.sessions',
'django.contrib.sites',
'project_name.app_name',
)
That is all
Upvotes: 2
Reputation: 599956
Your project structure is, not to put too fine a point on it, a mess. Some of the many things you need to do:
manage.py
and settings.py
should be in the outer level, not inside an application.views
is - is it actually views.py
? In which case it will never be used.templatetags
and views
should be __init__.py
, ie two underscores either side.Upvotes: 1
Reputation: 41674
Ae you sure this is specifically to do with the template tag?
It sounds like the project_name directory is not on your python path. The output on the error page should show your current python path, so you can check if it is as expected.
Read this to learn how to fix it: http://djangotricks.blogspot.com/2008/09/note-on-python-paths.html
Upvotes: 1