#21941: document kwargs parameter to url()
--------------------------------------+------------------------------------
     Reporter:  cjerdonek             |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  Documentation         |                  Version:  1.6
     Severity:  Normal                |               Resolution:
     Keywords:  url,kwargs            |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  1                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by mkaurkhalsa@…):

 == The url function can be explained as ==

 A convenient way to return the url pattern is url function :

 {{{
 url(regex, view, kwargs=None, name=None, prefix='')
 }}}


 Most of these are optional though. Lets demonstrate the use of all and few
 arguments in here

 {{{
 url(r'^index/$', index_view),
 url(r'^index/$', index_view, name="main-view"),
 url(r'^archive-summary/(\d{4})/$', archive, {'summary': True}, name="arch-
 summary"),
 url(r'^archive-summary/(\d{4})/$', archive, {'summary': True}, name="arch-
 summary" prefix='myapp'),
 }}}

 * The first url function has mandatory arguments where a url pattern
 points to some view named index_view.
 * It’s fairly common to use the same view function in multiple URL
 patterns in your URLconf. In those cases the second url function that is
 Naming URL Pattern([https://docs.djangoproject.com/en/dev/topics/http/urls
 /#naming-url-patterns]) is used.
 * In third url function, kwarg argument is used. url function can take an
 other optional argument which should be a dictionary of extra keyword
 arguments to pass to the view function.(Refer :
 [https://docs.djangoproject.com/en/dev/topics/http/urls/#passing-extra-
 options-to-view-functions] )
 * In the fourth url function prefix argument is used. When you name your
 URL patterns, make sure you use names that are unlikely to clash with any
 other application’s choice of names. If you call your URL pattern comment,
 and another application does the same thing, there’s no guarantee which
 URL will be inserted into your template when you use this name. Putting a
 prefix on your URL names, perhaps derived from the application name, will
 decrease the chances of collision. We recommend something like myapp-
 comment instead of comment.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/21941#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.bec970313504736951ae17f71fcb4632%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to