简体   繁体   English

具有多个应用程序的 Django 项目结构

[英]Django project structure with multiple apps

I intend to make a django project with multiple apps.我打算用多个应用程序制作一个 django 项目。 The main folder shall have a base.html which shall have links to different apps.主文件夹应该有一个 base.html 应该有链接到不同的应用程序。 The apps will have their own template directory.这些应用程序将有自己的模板目录。

-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

What are the configuration I should make in settings.py?我应该在 settings.py 中进行哪些配置?

Sandesh, Welcome to StackOverflow. Sandesh,欢迎来到 StackOverflow。

You should include the URLs from your apps in myprojects/urls.py like this:您应该在myprojects/urls.py中包含应用程序的 URL,如下所示:

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

And app1/urls.py :app1/urls.py

path('app1/', views.index)

Then on app1/views.py然后在app1/views.py

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

Having this structure would be enough to make those apps run in separate URLs.拥有这种结构就足以使这些应用程序在单独的 URL 中运行。 Then you can create a landing app which would have a base.html and has links to those apps.然后,您可以创建一个具有base.html并具有指向这些应用程序的链接的登陆应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM