django-Views之request(二)

时间:2022-07-23
本文章向大家介绍django-Views之request(二),主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

book/views.py

def index(request):
    http_list = {
        '<h1>请求协议:&nbsp;<span style="color:red">%s</span></h1>' % request.scheme,
        '<h1>获取完整地址:&nbsp;<span style="color:red">%s</span></h1>' % request.get_full_path(),
        '<h1>端口:&nbsp;<span style="color:red">%s</span></h1>' % request.get_port(),
        '<h1>请求方式:&nbsp;<span style="color:red">%s</span></h1>' % request.method,
        '<h1>完整url地址:&nbsp;<span style="color:red">%s</span></h1>' % request.get_raw_uri(),
    }
    return HttpResponse(http_list)

book/urls.py

from django.urls import path
from . import views
app_name ="book"
urlpatterns = [
    path('page/200/',views.index,name="index"),
]