If multiple view prefixes exist,

add multiple pattern() objects.

——————-

urlpatterns = patterns(’mysite.bizcard.views’,
(r’^$’, ‘home_page’),
(r’^page/$’, ‘listing’),
(r’^bizcardpost/$’, ‘picture_upload’),

)

urlpatterns +=patterns(‘mysite.bizentry.views’,

(r’^entry/$’,'bizentry’),

)

When string technique is used (rather than function) in URLconfs,

to reduce duplication, you can use view prefix.

—–

urlpatterns = patterns(”,
(r’^$’, ‘mysite.bizcard.views.home_page’),
(r’^page/$’, ‘mysite.bizcard.views.listing’),
(r’^bizcardpost/$’, ‘mysite.bizcard.views.picture_upload’),

)

will be changed with view prefix as follows:

urlpatterns = patterns(‘mysite.bizcard.views’,
(r’^$’, ‘home_page’),
(r’^page/$’, ‘listing’),
(r’^bizcardpost/$’, ‘picture_upload’),

)

Two types:

1. function object (need import view function)

2. string (don’t need to import)

——————

from django.conf.urls.defaults import *

from mysite.views import hi

urlpatterns = patterns(‘ ‘,

(r’^hi/$’, hi),

(r’^hello/$’, ‘mysite.views.hello’),

)

——–

Note in the first example,

hi

is a function object. This means you need to import the view function.

In second example,

‘mysite.views.hello’

is a string.

Here you don’t need to import it (Django will figure out)

© 2011 Web Oom Suffusion theme by Sayontan Sinha
Switch to our mobile site
Top Footer