I have a URL: http://localhost:8000/submit_workout/2/
我有一个URL: http://localhost:8000/submit_workout/2/
This URL was created with: r'^submit_workout/(?P<wr_id>\d+)/$'
这个URL创建了:r ^ submit_workout /(? P < wr_id > \ d +)/ $”
I am trying to retrieve "wr_id" when a form on that page is submitted.
当页面上的表单被提交时,我试图检索“wr_id”。
I'm trying: wr_id = request.GET.get('wr_id',None)
and am expecting wr_id=2 but keep getting wr_id=None returned.
我在尝试:wr_id= request.GET.get('wr_id',None),并期望wr_id=2,但不断返回wr_id=None。
Any thoughts? I am new to programming/django and really appreciate your time and expertise.
任何想法吗?我对编程/django是新手,非常感谢您的时间和专业知识。
1 个解决方案
#1
2
URL params, which are named in the url regex, can be passed as arguments to your method which handles the request. If your dispatcher looks like this:
URL params在URL regex中命名,可以作为参数传递给处理请求的方法。如果你的调度程序是这样的:
urlpatterns = patterns('',
(r'^submit_workout/(?P<wr_id>\d+)/$', 'submit_workout'),
Then your method should look like this:
那么你的方法应该是这样的:
def submit_workout(request, wr_id):
and wr_id
can be accessed directly.
可以直接访问wr_id。
If you want wr_id
to be a GET variable, then your url should look like this:
如果您希望wr_id是一个GET变量,那么您的url应该如下所示:
http://localhost:8000/submit_workout?wr_id=2
#1
2
URL params, which are named in the url regex, can be passed as arguments to your method which handles the request. If your dispatcher looks like this:
URL params在URL regex中命名,可以作为参数传递给处理请求的方法。如果你的调度程序是这样的:
urlpatterns = patterns('',
(r'^submit_workout/(?P<wr_id>\d+)/$', 'submit_workout'),
Then your method should look like this:
那么你的方法应该是这样的:
def submit_workout(request, wr_id):
and wr_id
can be accessed directly.
可以直接访问wr_id。
If you want wr_id
to be a GET variable, then your url should look like this:
如果您希望wr_id是一个GET变量,那么您的url应该如下所示:
http://localhost:8000/submit_workout?wr_id=2