修改Django布局结构后访问Django模板

编程入门 行业动态 更新时间:2024-10-28 06:22:26
本文介绍了修改Django布局结构后访问Django模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我按照以下方式重新组织了Django:

I re-organized Django,the following way:

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文件夹中,例如,标记,其他应用程序位于其他子文件夹中,即用户

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

我的问题是ng模板访问权限,因为出现以下错误:

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)

重复内部文件夹;

在视图中,模板设置为:

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

我也尝试过:

template_name = '/users/detail.html'

推荐答案

您不需要 users / templates / 前缀。只要您在 TEMPLATES 设置中具有'APP_DIRS':True ,应用目录加载程序就会检查 templates 目录,包括 users / templates

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'

更多推荐

修改Django布局结构后访问Django模板

本文发布于:2023-06-10 16:30:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/615065.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:布局   模板   结构   Django

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!