修改Django布局结构后访问Django Templates

Accessing Django Templates after modifing the Django layout structure

我重新组织了Django,方法如下:

config
 - settings
     - base.py
     - local.py
 urls.py
 wsgi.py  

还有应用:

- apps(level0)
  - acc(level_1)
   - users(level_2)
     - templates
       - users
    - acc_control(level_2)
  -att(level_1)
    - notes (level_2)
    - notifications (level_2)
  - mark(level_1)
- config (level0)
- templates(level0) 

有的应用直接在apps文件夹下,ex mark,有的在其他子文件夹下,ex users

   BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 


TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')]

我的问题与模板访问有关,因为我收到以下错误:

\apps\acc\users\templates\users\templates\users\detail.html (Source does not exist)

正在重复内部文件夹;

View中模板设置为:

 template_name = 'users/templates/users/detail.html'

我也试过:

 template_name = '/users/detail.html'

设置 template_name 时不需要 users/templates/ 前缀。只要您的 TEMPLATES 设置中有 'APP_DIRS': True,应用程序目录加载程序就会检查每个已安装应用程序的 templates 目录,包括 users/templates

template_name = 'users/detail.html'