1. 新建项目
第一个项目可以在图形化创建,但是后面的项目就需要在命令行创建了
# 新建一个test02项目python manage.py startapp test02# setting.py中配置项目INSTALLED_APPS = ['django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','test01.apps.Test01Config','test02' # <-- 新增test02]
2. 配置主项目引用子项目配置
from django.urls import includeurlpatterns = [path('test01/',include('test01.urls')), # 访问test01 到test01下的urls中找路径path('test02/',include('test02.urls')),]
3. 两个app分别创建urls.py
urlpatterns = [ path(‘index/‘,views.base), ]
视图
def base(request): return HttpResponse(‘
test01 index!
‘)
- **test02**```pythonfrom test02 import viewsurlpatterns = [path('index/',views.base),]# -- -- -- #def base(request):return HttpResponse('<h1>test02 index!</h1>')
4. 验证


