码迷,mamicode.com
首页 > 其他好文 > 详细

request response cookie session

时间:2019-05-21 17:22:49      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:user   weather   div   inline   图片   ack   mamicode   com   span   

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

标签:user   weather   div   inline   图片   ack   mamicode   com   span   

原文地址:https://www.cnblogs.com/py-web/p/10900929.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!