【问题标题】:Accessing Django Templates after modifing the Django layout structure修改 Django 布局结构后访问 Django 模板
【发布时间】:2018-06-19 13:27:19
【问题描述】:

我重新组织了 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) 

一些应用程序直接在应用程序文件夹中,前标记,其他应用程序在其他子文件夹中,前用户

   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'

【问题讨论】:

  • 这里没什么好说的。在错误页面中,您有一个很好的键值对表,显示每个设置配置的值是什么。对照您的实际路径检查并进行相应调整。

标签: django django-templates django-settings


【解决方案1】:

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

template_name = 'users/detail.html'

【讨论】:

  • 谢谢,第二次尝试没有成功,因为我在开头使用了'/'
猜你喜欢
  • 2017-05-28
  • 2021-06-17
  • 2016-01-03
  • 1970-01-01
  • 1970-01-01
  • 2023-03-23
  • 2015-04-24
  • 2012-10-28
  • 1970-01-01
相关资源
最近更新 更多