Django: Overriding AND extending an app template

前端 未结 6 2037
北荒
北荒 2020-12-02 18:05

If you want to override a template coming with an app in django (in app/templates/app/) you create a template of the same name in another directory, which the template loade

6条回答
  •  感情败类
    2020-12-02 18:57

    I think the answer from this related question is pertinent; currently, the best solution seems to be to use a custom template loader from the django-apptemplates package on PyPI, so you can just use pip to install it (e.g. pip install django-apptemplates).

    The template loader allows you to extend a template in a specific app; for example, to extend the index page of the admin inteface, you would add

    'apptemplates.Loader',
    

    to your TEMPLATE_LOADERS list in settings.py, and use

    {% extends "admin:admin/index.html" %}
    

    in your templates.

提交回复
热议问题