Discussion:
urlpatterns and generic views cheatsheet
DavidY
2008-08-23 12:11:28 UTC
Permalink
Here is a summary of all the tutorials and docs that I have read on
urlpatterns and generic views. It is a 2 page, concise, example code
based cheat sheet.

http://www.scribd.com/doc/4975790/urlpatterns-for-django-cheatsheet
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Idan
2008-08-24 18:59:28 UTC
Permalink
Useful! Thank you. :)

-I
Post by DavidY
Here is a summary of all the tutorials and docs that I have read on
urlpatterns and generic views. It is a 2 page, concise, example code
based cheat sheet.
http://www.scribd.com/doc/4975790/urlpatterns-for-django-cheatsheet
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Idan Gazit
2008-08-25 15:02:57 UTC
Permalink
Tim,

It's not terribly obvious from the scribd layout, but at the top
(above the document) there's a "download" link or similar, and there
you can download the original PDF.

-I
Post by DavidY
Here is a summary of all the tutorials and docs that I have
read on urlpatterns and generic views. It is a 2 page,
concise, example code based cheat sheet.
http://www.scribd.com/doc/4975790/urlpatterns-for-django-cheatsheet
Nifty, but scribd is annoying as heck.  Printing from scribd was
also an abysmal failure.  Whatever happened to just posting HTML
or a PDF somewhere?
-tim
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Tim Chase
2008-08-25 15:42:16 UTC
Permalink
Post by Idan Gazit
It's not terribly obvious from the scribd layout, but at the
top (above the document) there's a "download" link or similar,
and there you can download the original PDF.
...which expects that I create login...

Given that the source is likely just a PDF, posting a link to it
somewhere is a lot less painful than using Scribd. It's like
they (Scribd) asked the question "how can we best come between
site-visitors and the content our users want visitors to view?"
resulting in this solution. It's not like they're charging for
the content (AFAIK) so forcing me to create a login fails to net
them anything but useless marketing data, a plonk in my
cookie-jar, and a seething user that will now decry them at any
convenient opportunity.

</rant>

-tim






--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
rex
2008-08-25 17:23:17 UTC
Permalink
Post by Tim Chase
Post by Idan Gazit
It's not terribly obvious from the scribd layout, but at the
top (above the document) there's a "download" link or similar,
and there you can download the original PDF.
...which expects that I create login...
Copy & paste doesn't work. Trying to email it to myself results in
nothing happening.
Post by Tim Chase
Given that the source is likely just a PDF, posting a link to it
somewhere is a lot less painful than using Scribd. It's like
they (Scribd) asked the question "how can we best come between
site-visitors and the content our users want visitors to view?"
resulting in this solution. It's not like they're charging for
the content (AFAIK) so forcing me to create a login fails to net
them anything but useless marketing data, a plonk in my
cookie-jar, and a seething user that will now decry them at any
convenient opportunity.
Exactly my thoughts. This company has a solution to a non-existent
problem.
My account has been suspended/terminated for abuse! Will I get access to my documents?

All documents belonging to users that we have terminated for abuse
are deleted at the point of termination. Scribd will not provide
backups or access to these deleted documents.

How does Scribd define "abuse?"

Abuse is any activity that detracts from Scribd, or Scribd's
community.

IOW, your documents may vanish at the whim of Scribd, and they
cannot be recovered.

-rex

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
maeck
2008-08-25 19:56:33 UTC
Permalink
I have printed this from scribd into a PDF and use it as such, no need
for login.
Works somewhat, cannot select the text from it (could have run some
text recognition on it), but expect to find the original code or pdf
somewhere soon (Google code maybe).

maeck
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
DavidY
2008-08-26 11:56:34 UTC
Permalink
if you guys want the source here it is:

although if you just had emailed me to my mail account i might have
read this :p
i used pdf because it's sexy and colorful as opposed to the
following.


from django.conf.urls.defaults import *
urlpatterns = patterns('',
# (regular exp, function, optional dictionary, optional name)
# Doesn’t differentiate request method, all go to the same function
(r'^articles/2003/$', 'news.views.special_case_2003'),
# "/articles/2003" -> no match need "2003/"
(r'^articles/(\d{4})/$', 'news.views.year_archive'),
# ordering matters
# "/articles/2003/" -> news.views.special_case_2003, not
news.views.year_archive(2003)
(r'^articles/special/(?P<year>\d{4})/$',
'news.views.year_archive'),
# "/articles/special/2003" -> news.views.year_archive(request,
year='2003')
(r'^articles/(\d{4})/(\d{2})/$', 'news.views.month_archive'),
(r'^articles/(\d{4})/(\d{2})/(\d+)/$',
'news.views.article_detail'),
# "/articles/2003/03/3/" -> news.views.article_detail(request,
'2003', '03', '3')
)
urlpatterns += patterns('sports.views', # append like a list
(r'^sports/2003/$', 'some_function'),
# "/sports/2003/" -> sports.views.some_function(request)
)

# Generic actions are useful if you are doing something generic such
as:
# by default {'extra_context':{}}, add more context into extras if
necessary
urlpatterns += patterns('django.views.generic.simple',
(r'^page_new/(?P<id>\d+)/$', 'direct_to_template', {'template':
'page_detail.html'}),)
urlpatterns += patterns('django.views.generic.simple',
(r'^page/(?P<id>\d+)/$', 'redirect_to', {'url': '/page_new/%
(id)s/'}},)
urlpatterns += patterns('django.views.generic.list_detail',
(r'^page/all/$', 'object_list', {'queryset':
Pages.objects.all() }),)
# default: {'paginate_by':'infinity' , 'page':'1',
# 'template_name':'app/model_list.html' }
urlpatterns += patterns('django.views.generic.list_detail',
(r'^page/all/(?P<id>\d+)/$', 'object_detail', {'queryset':
Pages.objects.all(), 'object_id':id }),)
# default: {'paginate_by':'infinity' , 'page':'1',
# 'template_name':'app/model_detail.html' }
urlpatterns += patterns('django.views.generic.create_update',
(r'^...$', 'create_object', {'model':SomeModel or
'form_class':SomeForm }),)
# default: {'post_save_redirect':object.get_absolute_url(),
'login_required':False,
# 'template_name':'app/model_form.html' }
urlpatterns += patterns('django.views.generic.create_update',
(r'^...$', 'update_object', {'model': / 'form_class':,
'object_id':SomeID }),)
# default: {'post_save_redirect':object.get_absolute_url(),
'login_required':False,
# 'template_name':'app/model_form.html' }
urlpatterns += patterns('django.views.generic.create_update',
(r'^...$', 'delete_object', {'model': / 'form_class':,
'object_id':SomeID }),)
# default: {'post_save_redirect':object.get_absolute_url(),
'login_required':False,
# 'template_name':'app/model_confirm_delete.html' }

# Parents are good for subdividing the work
urlpatterns += patterns('', # use include to add child url matchers:
(r'^weblog/(?P<idName>\w+)/', include('mysite.app.url')),
)
# in file app/url.py:
from django.conf.urls.defaults import *
urlpatterns = patterns('app.views',
(r'^$', 'blog.index'),
# "/weblog/me/" -> app.views.blog.index(request, idName='me')
(r'^post/(?P<postIndex>\d+)$', 'post.show'),
# "/weblog/me/12" -> app.views.post.show(request, idName='me',
postIndex='12')
(r'^details/$', 'blog.details', {'extraData', 'foo!'})
# "/weblog/details/" -> app.views.blog.details(request, idName='me',
extraData='foo!')
(r'^post/(?P<pid>\d+)/comment/(?P<cid>\d+)/$', 'post.show',
{'gotoComment', 'true'}, "weblog-viewComment"),
# "/weblog/post/1/comment/1/" -> app.views.blog.details(request,
idName='me', pid='1', cid='1', gotoComment='true')
# the template tag {% url weblog-viewComment pid=1,cid=1 %} returns "/
weblog/post/1/comment/1/"
)

# often you will write one function which has a default parameter to
save code:
urlpatterns = patterns('app.views',
(r'^$', 'blog.index'),
(r'^/(?P<postIndex>\d+)/$', 'blog.index'))
def index(request, postIndex='1')
....

# often we want to find a url that will execute a function with some
parameters
# we would use {% url function args %} in a template. in code we would
use:
from django.core.urlresolvers import reverse
reverse(viewname, urlconf=None, args=None, kwargs=None)
def myview(request):
return HttpResponseRedirect(reverse('weblog-viewComment',
args='pid=1,cid=1'))

# regular reference:
# . any char
# ^ start of string $ end of string
# * 0 or more of preceding + 1 or more of preceding
# ? 0 or 1 of preceding (?!..) matches when it doesnt
match ..
# *? 0 or more, minimal match +? 1 or more, minimal
match
# {m} exactly m of preceding {m,n} between m to n of
preceding
# [..] eg. [abc],[a-z],[0-9a-z] [^..] matches if doesn't
match [..]
# (..) groups what's inside (?=..) matches .. but doesn't
consume it
# \d [0-9] (decimal digit) \D [^0-9] (non-digit)
# \w [a-zA-Z0-9_] (alphanumeric) \W [^a-zA-Z0-9_] (non-
alphanumeric)
# \s [ \t\n\r\f\v] (whitespace) \S [^ \t\n\r\f\v] (non-
whitespace)

# Request and Response Object
def index(request, index='1')
request.path # /weblog/me/
request.method # either 'GET', 'POST', 'HEAD', ...
request.GET['someVarName'] # whatever it should be
request.GET['someVarName', 'default'] # if it doesn't exist then
default. also for POST
request.POST['someVarName']
request.REQUEST['someName'] # searches GET then FILES
request.COOKIES['attributeName']
request.FILES['someFilename'] # request.POST does not have files
# includes methods: read(num_bytes=...), chunk() and attrs:
file_name, file_size
request.META['someMetaName']
# includes: CONTENT_LENGTH, CONTENT_TYPE, HTTP_ACCEPT_ENCODING,
SERVER_PORT,
# HTTP_ACCEPT_LANGUAGE, HTTP_HOST, HTTP_REFERER, HTTP_USER_AGENT,
# QUERY_STRING, REMOTE_ADDR, REMOTE_HOST, REQUEST_METHOD,
SERVER_NAME,
request.user # object: django.contrib.auth.models.User
request.get_full_path() # includes any stuff after the last
directory /
request.build_absolute_uri() # includes a http://www.. bit that is
read from their side
request.is_ajax() # major ajax libraries send a signal that a query
is for ajax
Post by maeck
I have printed this from scribd into a PDF and use it as such, no need
for login.
Works somewhat, cannot select the text from it (could have run some
text recognition on it), but expect to find the original code or pdf
somewhere soon (Google code maybe).
maeck
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Álvaro J. Iradier
2008-08-28 11:57:08 UTC
Permalink
I can't download from scribd. I need to register, but it's impossible,
as the flash viewer overlaps and hides the registration text fields.
Printing also fails...

Would it be possible to download this cheatsheets from somewhere else?
Anyone that got the pdfs could post them somewhere?

Thanks very much.
Post by Idan Gazit
Tim,
It's not terribly obvious from the scribd layout, but at the top
(above the document) there's a "download" link or similar, and there
you can download the original PDF.
-I
Post by Tim Chase
Post by DavidY
Here is a summary of all the tutorials and docs that I have
read on urlpatterns and generic views. It is a 2 page,
concise, example code based cheat sheet.
http://www.scribd.com/doc/4975790/urlpatterns-for-django-cheatsheet
Nifty, but scribd is annoying as heck. Printing from scribd was
also an abysmal failure. Whatever happened to just posting HTML
or a PDF somewhere?
-tim
--
(:===========================================:)
Alvaro J. Iradier Muro - ***@gmail.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Tim Chase
2008-08-25 14:50:02 UTC
Permalink
Post by DavidY
Here is a summary of all the tutorials and docs that I have
read on urlpatterns and generic views. It is a 2 page,
concise, example code based cheat sheet.
http://www.scribd.com/doc/4975790/urlpatterns-for-django-cheatsheet
Nifty, but scribd is annoying as heck. Printing from scribd was
also an abysmal failure. Whatever happened to just posting HTML
or a PDF somewhere?

-tim




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com
To unsubscribe from this group, send email to django-users+***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Loading...