1:建立新工程:python
django-admin startproject anotherurl
2:在工程下建立app:django
django-admin startapp app
3:在項目app中建立urls.py文件,內容以下:app
from django.urls import path from app import views urlpatterns = [ path('home/', views.home, name='home'), ]
添加簡單的視圖函數:ide
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/url