request response cookie session
Posted py-web
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了request response cookie session相关的知识,希望对你有一定的参考价值。
request
1. url传递参数
1)参数没有命名, 如:
users/views
def weather(request, city, year): print(city) print(year) return HttpResponse(‘OK‘)
users/urls
from django.conf.urls import url from . import views urlpatterns = [ # url(路径, 视图) url(r‘^weather/([a-z]+)/(\\d{4})/$‘, views.weather, name=‘weather‘), ]
2) 参数命名, 如
from django.conf.urls import url from . import views urlpatterns = [ # url(路径, 视图) # url(r‘^weather/([a-z]+)/(\\d{4})/$‘, views.weather, name=‘weather‘), url(r‘^weather/(?P<city>[a-z]+)/(?P<year>\\d{4})/$‘, views.weather), ]
(?P<city> 就是给参数命名为city
以上是关于request response cookie session的主要内容,如果未能解决你的问题,请参考以下文章
response中的set-cookie和request中的cookie
request response cookie session
response.addCookie(cookie)添加cookie失败.