What is the best location to put templates in django project?

后端 未结 9 610
情歌与酒
情歌与酒 2020-12-07 13:29

What is the best location to put templates in django project?

相关标签:
9条回答
  • 2020-12-07 13:50

    I understood TEMPLATE_DIRS requires an absolute path. And I don't like absolute paths in my code. So this is working well for me, in settings.py:

    import os
    
    TEMPLATE_DIRS = (
        os.path.join(os.path.dirname(os.path.realpath(__file__)),
                     "../APPNAME/templates")
    )
    
    0 讨论(0)
  • 2020-12-07 13:52

    Placed in <PROJECT>/<APP>/templates/<APP>/template.html for app-specific templates to help with making the app reusable elsewhere.

    For general "global" templates I put them in <PROJECT>/templates/template.html

    0 讨论(0)
  • 2020-12-07 13:57

    Previous solution didn't work in my case. I used:

    TEMPLATE_DIRS = [ os.path.join(os.path.dirname(os.path.realpath(__file__)),"../myapp/templates") ]
    
    0 讨论(0)
提交回复
热议问题