Accessing Django Templates after modifing the Django layout structure

不羁的心 提交于 2019-12-24 18:55:39

问题


I re-organized Django,the following way:

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

also apps:

- 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) 

Some apps are directly in apps folder, ex mark, others are in other subfolders, 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')]

My issue is regarding templates access, because I receive the following error:

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

is repeating the internal folder;

In the View the template is set as:

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

I tried also:

 template_name = '/users/detail.html'

回答1:


You don't need the users/templates/ prefix when you set template_name. As long as you have 'APP_DIRS': True in your TEMPLATES setting, the app directories loader will check the templates directory for every installed app, including users/templates

template_name = 'users/detail.html'


来源:https://stackoverflow.com/questions/48186359/accessing-django-templates-after-modifing-the-django-layout-structure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!