1、创建项目

    1. django-admin startproject MyDjango

    2、创建应用

    1. python3 manage.py startapp news

    3、配置主路由
    MyDjango > MyDjango > urls.py

    1. from django.urls import path,include
    2. urlpatterns = [
    3. path('news/', include('news.urls'))
    4. ]

    4、配置子路由
    MyDjango > news > urls.py

    1. from django.urls import path
    2. from . import views
    3. urlpatterns = [
    4. path('<int:new_id>/', views.detail, name='detail')
    5. ]

    5、自定义视图
    MyDjango > news > views.py

    1. from django.http import HttpResponse
    2. def detail(request, new_id):
    3. response = 'Show new with %s'
    4. return HttpResponse(response % new_id)

    6、运行内置服务器

    1. python3 manage.py runserver 8080

    7、浏览器请求