Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To clarify camflan's explanation, let's suppose you have</p> <ul> <li>the rule <code>url(regex=r'^user/(?P&lt;username&gt;\w{1,50})/$', view='views.profile_page')</code></li> <li>a in incoming request for <code>http://domain/user/thaiyoshi/?message=Hi</code></li> </ul> <p>The URL dispatcher rule will catch parts of the URL <em>path</em> (here <code>"user/thaiyoshi/"</code>) and pass them to the view function along with the request object.</p> <p>The query string (here <code>message=Hi</code>) is parsed and parameters are stored as a <code>QueryDict</code> in <code>request.GET</code>. No further matching or processing for HTTP GET parameters is done.</p> <p>This view function would use both parts extracted from the URL path and a query parameter:</p> <pre><code>def profile_page(request, username=None): user = User.objects.get(username=username) message = request.GET.get('message') </code></pre> <p>As a side note, you'll find the request method (in this case <code>"GET"</code>, and for submitted forms usually <code>"POST"</code>) in <code>request.method</code>. In some cases it's useful to check that it matches what you're expecting.</p> <p><strong>Update:</strong> When deciding whether to use the URL path or the query parameters for passing information, the following may help:</p> <ul> <li>use the URL path for uniquely identifying resources, e.g. <code>/blog/post/15/</code> (not <code>/blog/posts/?id=15</code>)</li> <li>use query parameters for changing the way the resource is displayed, e.g. <code>/blog/post/15/?show_comments=1</code> or <code>/blog/posts/2008/?sort_by=date&amp;direction=desc</code></li> <li>to make human friendly URLs, avoid using ID numbers and use e.g. dates, categories and/or slugs: <code>/blog/post/2008/09/30/django-urls/</code></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload