如题所述
可以的:
url中需要相应定义:
例一:
urls.pyurlpatterns = [
url(r'^add/(\d+)/(\d+)$', views.add, ),
]
views.py
def add(request,a,b):
c=int(a)+int(b)
return HttpResponse(str(c))
例二:
urlpatterns = [
url(r'^add3/(?P<username>\w+)/(?P<user_id>\d+)/', views.add3, name="add3"),
]
此处username,user_id,在views对应的函数里,参数命名时必须 与url中的命名一致
view.py
def add3(request,username,user_id):
return HttpResponse("username:" + username + ",user_id:" + user_id)
温馨提示:答案为网友推荐,仅供参考