Reputation: 66320
A while back I was given the advice to not use the GET approach in my urls when using Django as it's cleaner this way.
That works pretty nice with one parameter:
(r'^call/add/(?P<call_id>\d+)/$', call_view),
http://127.0.0.1:8000/call/add/1/
But how could I possibly use the same approach with two parameters?
As I am still learning, please enlighten me about better approaches. Thank you.
Upvotes: 3
Views: 282
Reputation: 892
(r'^call/add/(?P<call_id>\d+)/(?P<receiver_id>\d+)/$', call_view),
http://127.0.0.1:8000/call/add/1/903256
and you need to add def call_view(request, call_id, receiver_id):
in views.py
or you can you w+
instead of d+
to pass string a a variable
(r'^call/add/(?P<call_id>\d+)/(?P<receiver_name>\w+)/$', call_view),
http://127.0.0.1:8000/call/add/1/Kave
For more info : https://docs.djangoproject.com/en/dev/topics/http/urls/
Upvotes: 2
Reputation: 4457
You simply can add another on the back like http://127.0.0.1:8000/call/add/1/foo/2
. You have to add the second parameter to the regular expression as well like (r'^call/add/(?P<call_id>\d+)/foo/(?P<foo_id>\d+)$', call_view),
.
You have to change the controller as well: def call_view(request, call_id, foo_id):
Upvotes: 3
Reputation: 122326
You can specify multiple parameters as follows:
(r'^call/add/(?P<call_id>\d+)/(?P<other_value>\d+)/$', call_view),
and you view should look like this:
def call_view(request, call_id, other_value):
# view code here
Upvotes: 2