【发布时间】:2023-01-20 16:55:55
【问题描述】:
我在 django 项目中有 2 个 index.html 文件,但在不同的应用程序中。我怎样才能为他们每个人单独直接展示?
def index(request):
return render(request, 'index.html')
【问题讨论】:
标签: django django-views django-templates
我在 django 项目中有 2 个 index.html 文件,但在不同的应用程序中。我怎样才能为他们每个人单独直接展示?
def index(request):
return render(request, 'index.html')
【问题讨论】:
标签: django django-views django-templates
创建以下文件夹结构
- app1
-- templates
--- app1
---- index.html
- app2
-- templates
--- app2
---- index.html
然后在 app1 的 views.py 中
def index(request):
return render(request, 'app1/index.html')
该文件夹结构称为命名空间。阅读here“模板命名空间”部分
【讨论】: