Base template for all apps in Django

前端 未结 3 1215
渐次进展
渐次进展 2021-02-07 02:01

I have a project with 2 apps

project/
    blog/
        templates/
            index.html
    polls/
        templates/
            index.html
    project/
              


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-07 02:47

    In current Django (1.10) TEMPLATE_DIRS is deprecated, so:

    1. Add a templates directory at the project root,
    2. In settings.py find TEMPLATES -> DIRS and add it like this:

      TEMPLATES = [
      {
          ...
          'DIRS': [(os.path.join(BASE_DIR, 'templates')),],
          ...
      }
      
    3. Add a base.html to that directory.

    4. Extend it wherever you want using {% extends 'base.html' %}

提交回复
热议问题