1、创建项目
django-admin startproject MyDjango
2、创建应用
python3 manage.py startapp news
3、配置主路由
MyDjango > MyDjango > urls.py
from django.urls import path,include
urlpatterns = [
path('news/', include('news.urls'))
]
4、配置子路由
MyDjango > news > urls.py
from django.urls import path
from . import views
urlpatterns = [
path('<int:new_id>/', views.detail, name='detail')
]
5、自定义视图
MyDjango > news > views.py
from django.http import HttpResponse
def detail(request, new_id):
response = 'Show new with %s'
return HttpResponse(response % new_id)
6、运行内置服务器
python3 manage.py runserver 8080
7、浏览器请求