vim django-20231002/mysite/polls/views.py
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
return HttpResponse('hello django polls index')
def q_detail(request,question_id):
return HttpResponse('you are looking for %s.'%question_id)
vim django-20231002/mysite/polls/urls.py
from django.urls import path
from . import views
urlpatterns=[
path('index/',views.index),
path('question/detail/<int:question_id>/',views.q_detail),
]
演示
请求http://localhost:8000/polls/question/detail/1/
links:
https://www.w3cschool.cn/django4/django4-esfw3lyr.html