Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
56Activity
0 of .
Results for:
No results containing your search query
P. 1
urlpatterns for django cheatsheet

urlpatterns for django cheatsheet

Ratings:

4.5

(14)
|Views: 16,185|Likes:
Published by windoze007
Quick and simple urlpatterns code examples for django cheatsheet
Quick and simple urlpatterns code examples for django cheatsheet

More info:

Published by: windoze007 on Aug 23, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

10/18/2013

pdf

text

original

 
django_url_cheat.txtPage 1 of 2 Aug/2008
1
from
django.conf.urls.defaults
import
 *2 urlpatterns=patterns('', 3# (regular exp, function, optional dictionary, optional name)4# Doesn’t differentiate request method, all go to the same function5(r'^articles/2003/$', 'news.views.special_case_2003'),  6# "/articles/2003" -> no match need "2003/"7(r'^articles/(\d{4})/$', 'news.views.year_archive'), 8# ordering matters9# "/articles/2003/" -> news.views.special_case_2003, not news.views.year_archive(2003)10(r'^articles/special/(?P<year>\d{4})/$', 'news.views.year_archive'), 11# "/articles/special/2003" -> news.views.year_archive(request, year='2003')12(r'^articles/(\d{4})/(\d{2})/$', 'news.views.month_archive'), 13(r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'news.views.article_detail'), 14# "/articles/2003/03/3/" -> news.views.article_detail(request, '2003', '03', '3')15)16 urlpatterns+=patterns('sports.views', # append like a list 17(r'^sports/2003/$', 'some_function'), 18# "/sports/2003/" -> sports.views.some_function(request)19)2021# Generic actions are useful if you are doing something generic such as:22# by default {'extra_context':{}}, add more context into extras if necessary23 urlpatterns+=patterns('django.views.generic.simple',  24(r'^page_new/(?P<id>\d+)/$', 'direct_to_template', {'template': 'page_detail.html'}),) 25 urlpatterns+=patterns('django.views.generic.simple',  26(r'^page/(?P<id>\d+)/$', 'redirect_to', {'url': '/page_new/%(id)s/'}},) 27 urlpatterns+=patterns('django.views.generic.list_detail',  28(r'^page/all/$', 'object_list', {'queryset':Pages.objects.all() }),) 29# default: {'paginate_by':'infinity' , 'page':'1',30# 'template_name':'app/model_list.html' }31 urlpatterns+=patterns('django.views.generic.list_detail',  32(r'^page/all/(?P<id>\d+)/$', 'object_detail', {'queryset':Pages.objects.all(), 'object _id':id}),) 33# default: {'paginate_by':'infinity' , 'page':'1',34# 'template_name':'app/model_detail.html' }35 urlpatterns+=patterns('django.views.generic.create_update',  36(r'^...$', 'create_object', {'model':SomeModel
or
 'form_class':SomeForm}),) 37# default: {'post_save_redirect':object.get_absolute_url(), 'login_required':False,38# 'template_name':'app/model_form.html' }39 urlpatterns+=patterns('django.views.generic.create_update',  40(r'^...$', 'update_object', {'model': / 'form_class':, 'object_id':SomeID}),) 41# default: {'post_save_redirect':object.get_absolute_url(), 'login_required':False,42# 'template_name':'app/model_form.html' }43 urlpatterns+=patterns('django.views.generic.create_update',  44(r'^...$', 'delete_object', {'model': / 'form_class':, 'object_id':SomeID}),) 45# default: {'post_save_redirect':object.get_absolute_url(), 'login_required':False,46# 'template_name':'app/model_confirm_delete.html' }4748# Parents are good for subdividing the work49 urlpatterns+=patterns('', # use include to add child url matchers: 50(r'^weblog/(?P<idName>\w+)/',include('mysite.app.url')), 51)52# in file app/url.py:53
from
django.conf.urls.defaults
import
 *54 urlpatterns=patterns('app.views', 55(r'^$', 'blog.index'),  56# "/weblog/me/" -> app.views.blog.index(request, idName='me')57(r'^post/(?P<postIndex>\d+)$', 'post.show'), 58# "/weblog/me/12" -> app.views.post.show(request, idName='me', postIndex='12')59(r'^details/$', 'blog.details', {'extraData', 'foo!'}) 60# "/weblog/details/" -> app.views.blog.details(request, idName='me', extraData='foo!')61(r'^post/(?P<pid>\d+)/comment/(?P<cid>\d+)/$', 'post.show', {'gotoComment', 'true'}, "w eblog-viewComment"),62# "/weblog/post/1/comment/1/" -> app.views.blog.details(request, idName='me', pid='1',cid='1', gotoComment='true')
- 1 -

Activity (56)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Manish Sharma liked this
dnivie liked this
NeilJuan Juan liked this
jbakke00 liked this
Hanse69 liked this
Hanse69 liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->