响应HTML内容
def hello_world(request):html='<html><body><p style="color:red">这个是标题</p></body></html>'return HttpResponse(html)
获取URL参数(通过month获取url参数)
#视图函数def article(request,month):return HttpResponse('article:'+str(month))
#urls.pyurlpatterns = [path('world/',hello_world,name='hello_world'),path('article/<int:month>',views.article,name='article_list')]
获取URL中的正则匹配的参数
比如月份:re_path(r'^article/(?p<month>0?[1-9]|1[012]/$)',views.article,name='article_list')
获取get参数
输入URL:http://127.0.0.1:8000/search?name=五月天视图编写:def search(request):name=request.GET.get('name',None)
