Django project base template

后端 未结 5 942
忘掉有多难
忘掉有多难 2020-12-23 03:06

Can I create a base template for my project which all apps can draw from? Or do I have to create a base template for each app? And if I wanted them to be the same I\'d jus

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-23 04:06

    Yes, you can create a base template for your project that other apps will extend. Check @Kenny_Shen answer on how.

    Just wanted to add two notes if you are concerned about app isolation.

    1. If you do not want your app to rely on the "base.html" naming convention, you can inject the actual name with a variable, take a look at: How do I use Django's template extends variable? for details,

    2. You might want to name the app template block to something else, not "content" to avoid collisions with other apps.

提交回复
热议问题