python - How to create a custom django filter tag -
i having trouble in getting site recognise custom template tags. have following dir structure:
- project_name
- project_name
- templatetags
- _ __init __ _.py
- getattribute.py
- views
- _ __init __ _.py
- index.html
- views
- settings.py
- main.py
- manage.py
- urls.py
- templatetags
- nbproject
- project_name
then have added installed_apps:
installed_apps = ( # 'django.contrib.auth', 'django.contrib.contenttypes', # 'django.contrib.sessions', 'django.contrib.sites', 'project_name' )
i reference inside template this:
{% load getattribute %} {% header in headers %} <td>{{ obj|getattribute:header }}</td> {% endfor %}
the error follows:
could not import controllers.eventcontroller. error was: no module named project_name
any appreciated this:
tia
andrew
update:
the site works cannot template tags work. if remove project_name installed_apps following error:
exception value: 'getattribute' not valid tag library: not load template library django.templatetags.getattribute, no module named getattribute
the error becaus have wrong folder's structure, think must read docs, tutorial (part1) explains right structure:
you have project isn't same thing app:
- project_name
- app_name
- templatetags
- getattribute.py
- models.py
- views.py
- templatetags
- app_name
- settings.py
- manage.py
and in installed_apps
:
installed_apps = ( # 'django.contrib.auth', 'django.contrib.contenttypes', # 'django.contrib.sessions', 'django.contrib.sites', 'project_name.app_name', )
that all
Comments
Post a Comment