【问题标题】:Django project structure with multiple apps具有多个应用程序的 Django 项目结构
【发布时间】:2020-05-27 07:59:40
【问题描述】:

我打算制作一个包含多个应用程序的 django 项目。主文件夹应有一个 base.html,其中应包含指向不同应用程序的链接。应用程序将拥有自己的模板目录。

-myproject
    -__init__.py
    -settings.py
    -views.py
    -urls.py
    -admin.py
    -test.py

-app1
    -templates
        -abc.html
    -views.py
    -urls.py

-app2
    -templates
        -abc2.html
    -views.py
    -urls.py

我应该在settings.py中进行哪些配置?

【问题讨论】:

    标签: python django django-templates


    【解决方案1】:

    Sandesh,欢迎使用 StackOverflow。

    您应该在myprojects/urls.py 中包含您应用的网址,如下所示:

    [path('', include('app1.urls')),]
    

    还有app1/urls.py:

    path('app1/', views.index)
    

    然后在app1/views.py

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

    拥有这种结构就足以使这些应用程序在单独的 URL 中运行。然后,您可以创建一个登陆应用程序,该应用程序将具有 base.html 并具有指向这些应用程序的链接。

    【讨论】:

      猜你喜欢
      • 2016-04-13
      • 2015-07-09
      • 1970-01-01
      • 1970-01-01
      • 2012-09-26
      • 1970-01-01
      • 2021-06-04
      • 2019-03-18
      • 2012-09-28
      相关资源
      最近更新 更多