标签:coding 属性 web im www new bsp mil 用户 port
# -*- coding: utf-8 -*-from __future__ import unicode_literalsfrom django.http import HttpResponsedef index(request):return HttpResponse("<h1>index</h1>")def login(request,userName,passWord):if passWord == ‘test1234_‘:return HttpResponse("%s,欢迎登录!" %(userName))else:return HttpResponse(‘用户名和密码错误‘)
from web.views import index,loginurlpatterns = [url(r‘^index/$‘,index),]
3. 使用正则中的分组方法进行参数传递,不指定参数名,按传入顺序 接收。from web import viewsurlpatterns = [url(r‘^index/$‘, views.index),]
输入正确时:输入错误时:
from web import viewsurlpatterns = [url(r‘^index/$‘,views.index),url(r‘^login/(?P<passWord>\w+)/(?P<userName>\w+)$‘,views.login),]
5. 固定参数(passWord 属性为固定参数,即使你传入正确的密码“test1234_”,也会显示用户名和密码错误,因为login方法实际接收到的值固定为“test1234”)输入正确时:输入错误时:
urlpatterns = [url(r‘^index/$‘, views.index),url(r‘^login/(?P<userName>\w+)‘, views.login, {‘passWord‘:‘test1234‘}),]
urlpatterns = [url(‘^web/‘,include(‘web.urls‘)),]
url(‘^index/$‘, views.index),url(‘^login/(?P<userName>\w+)/(?P<passWord>\w+)$‘, views.login),]
标签:coding 属性 web im www new bsp mil 用户 port
原文地址:http://www.cnblogs.com/PythonHomePage/p/7634380.html