Accessing Django Templates after modifing the Djan

2019-08-03 10:11发布

问题:

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'