1:创建新工程:
django-admin startproject anotherurl
2:在工程下创建app:
django-admin startapp app
3:在项目app中创建urls.py文件,内容如下:
from django.urls import path from app import views urlpatterns = [ path('home/', views.home, name='home'), ]
添加简单的视图函数:
from django.shortcuts import render,HttpResponse # Create your views here. def home(request): return HttpResponse("首页")
4:在工程urls添加子路由
from django.contrib import admin from django.urls import path,include import app urlpatterns = [ path('admin/', admin.site.urls), path('blog/', include("app.urls")), ]
启动访问blog/home/