djangodjango-1.7

Use custom directory for "templatetags"


some one know if its likely use custom directory for "templatetags" eje: "my-project/templatetags"

Normal
My-Project-Name
  My-App
    __init__.py
      templatetags
        __init__.py

Need Some Like This

My-Project-Name
  templatetags
    __init__.py

Solution

  • This is not possible. The reason being, templatetags must reside inside a django app.

    From the documentation of templatetags:

    Custom template tags and filters must live inside a Django app. If they relate to an existing app it makes sense to bundle them there; otherwise, you should create a new app to hold them.

    The app should contain a templatetags directory, at the same level as models.py, views.py, etc. If this doesn’t already exist, create it - don’t forget the __init__.py file to ensure the directory is treated as a Python package. After adding this module, you will need to restart your server before you can use the tags or filters in templates.