Frage

I have a django project with the next folder structure:

+ project
+ - - app_1
+ - - - - __init__.py
+ - - - - models.py
+ - - - - forms.py
+ - - - - urls.py
+ - - - - templates
+ - - - - - - index.html
+ - - - - - - edit.html
+ - - - - - - show.html
+ - - - - views
+ - - - - - - __init__.py
+ - - - - - - index.py
+ - - - - - - edit.py
+ - - - - - - show.py
+ - - - - - - templatetags
+ - - - - - - - - __init__.py
+ - - - - - - - - custom_tags.py

When I try to call the custom_tags in the edit.html template for example

{% load custom_tags %}

I get the next error:

TemplateSyntaxError at /app_1/

'custom_tags' is not a valid tag library: Template library custom_tags not found

My question is: Where i need put the templatetags folder or what i need to do ?

Thanks.

War es hilfreich?

Lösung

Try moving your templatetags directory one level up, to right under your app_1 directory (as in https://docs.djangoproject.com/en/dev/howto/custom-template-tags/).

Andere Tipps

The templatetags folder should be in the app folder:

+ project
+ - - app_1
+ - - - - __init__.py
+ - - - - templatetags
+ - - - - - - __init__.py
+ - - - - - - custom_tags.py

Depending on your server, you may need to restart it.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top