【问题标题】:I have 2 index.html files in django project, how to show direct separately我在django项目中有2个index.html文件,如何分别直接显示
【发布时间】:2023-01-20 16:55:55
【问题描述】:

我在 django 项目中有 2 个 index.html 文件,但在不同的应用程序中。我怎样才能为他们每个人单独直接展示?

def index(request):
  return render(request, 'index.html')

【问题讨论】:

    标签: django django-views django-templates


    【解决方案1】:

    创建以下文件夹结构

    - app1
    -- templates
    --- app1
    ---- index.html
    - app2
    -- templates
    --- app2
    ---- index.html
    

    然后在 app1 的 views.py 中

    def index(request):
      return render(request, 'app1/index.html')
    

    该文件夹结构称为命名空间。阅读here“模板命名空间”部分

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-21
      • 1970-01-01
      • 2022-09-27
      • 2020-07-29
      • 1970-01-01
      • 2017-09-24
      • 2012-06-10
      • 2016-05-27
      相关资源
      最近更新 更多