Synthax to declare urls in django -
i'm not sure understand difference between 2 urls below
from django.conf.urls import patterns, url main_app import views urlpatterns = patterns('', url(r'^$', views.main, name='home'), (r'^accounts/$', views.accounts, name="account"), ... ) both working me. should use 1 instead of other? why? examples found reffering first synthax i'd understand why.
the first syntax, using url function, allows pass dictionary of keyword arguments view.
https://docs.djangoproject.com/en/dev/topics/http/urls/#passing-extra-options-to-view-functions
from documentation:
urlpatterns = patterns('blog.views', url(r'^blog/(?p<year>\d{4})/$', 'year_archive', {'foo': 'bar'}), ) in example, request /blog/2005/, django call
blog.views.year_archive(request, year='2005', foo='bar')
Comments
Post a Comment