I am currently going through various Django tutorials in order to understand how url mapping is working . I came across an example which is something like this
this is in my urls.py
url(r'admin_page_edit$',"adminApp.views.showClientDetails",name="admin_page_edit"),
this is in my html page that is currently being displayed to the user
<a href="{% url "admin_page_edit" %}?uname=SomeVal&par2=value" >
Now the URL the browser shows when the above href link is clicked. No problem there
http://127.0.0.1:8000/admin_page_edit?uname=SomeVal&par2=value
And the above URL lands in the corresponding view
adminApp.views.showClientDetails
Now here is the proble, this seems to all work but I am confused as to why this is working ? since the url of the browser is
http://127.0.0.1:8000/admin_page_edit?uname=SomeVal&par2=value
which does not match the regex string in the url
admin_page_edit$
(The above regex means if the string ends with admin_page_edit
) but the url string does not end with admin_page_edit
instead it is
http://127.0.0.1:8000/admin_page_edit?uname=SomeVal&par2=value
thus ending with par2=value
My question is why is this hitting the corresponding definition in the view when the url regex is not matching ?
Query strings (parts following ?
) are not processed by the Django url parser. Why? Because they don't have to be processed. You can just about append any query string to any url:
Like: https://www.facebook.com/?request=pleasedonotwork which works all the same. Unless redirects (or some logging) are done based on queries sent in urls, you can consider the query part of urls as passive.
These query strings can be accessed in your Django views via the request.GET
QueryDict