[Django]-How pass two parameters to url (without GET)?

3👍

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):

👤fdomig

2👍

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

2👍

(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/

👤iraycd

Leave a comment