5π
Do not modify or add anything to directory containing Django (do not modify Django!). Keep everything in your project directory (like in the manual).
Admin templates are exactly the same as non-admin templates and you use custom template tags exactly the same way. Put your template tags in yourapp/templatetags/
directory. If your app is in the settings.INSTALLED_APPS
that you can load itβs tags by passing the module name to the load tag. It accepts also package.module
syntax, so: {% load somelibrary %}
or {% load package.otherlibrary %}
0π
The easiest way is to copy templatetags
folder from /django/contrib/admin/templatetags
in your virtual environment to core
folder where settings.py
is, then create custom_tags.py
in templatetags
folder as shown below, then donβt forget to restart server to apply all .py
files except __init__.py
to Django project. *You can also override the code like the tags or filters in admin_list.py
, admin_modify.py
, admin_urls.py
, base.py
and log.py
and you can see my answer explaining templatetags folder and load tag:
Django Project
|-core
| |-settings.py
| β-templatetags # Here
| |-__pycache__
| |-__init__.py
| |-admin_list.py
| |-admin_modify.py
| |-admin_urls.py
| |-base.py
| |-log.py
| β-custom_tags.py # Here
|-templates
| β-admin
| β-model
| β-change_list.html
|-app1
β-app2
Then in change_list.html
, load the custom tags in custom_tags.py
as shown below:
# "/templates/admin/model/change_list.html"
# β Here β
{% load i18n admin_urls static admin_list custom_tags %}
- [Django]-Haystack Multiple Indices β indexed same even there are different search_indexes
- [Django]-Django: reverse function fails with an exception
- [Django]-POSTing foreign keys to Django Rest Framework, using Postman