Previous Page Next Page

Calling the View Functions Directly

Django supports an alternative method of calling the view functions from the URLconf file. Instead of pointing to the location of the view function using a .-based syntax string, you can import the function into the URLconf file and then use the function name instead. For example, if your current view file contains the following URL patterns that point to an index() and display() view functions:

(r'^Blog/List/$', 'iFriends.Blog.views.index'),
(r'^Blog/Display/$', 'iFriends.Blog.views.display'),

you could import the index() and display() view functions in the URLconf file using the following line of code:

from iFriends.Blog.views import index, display

and then you could pass callable function objects directly using the following code:

(r'^Blog/List/$', index),
(r'^Blog/Display/$', display),

Previous Page Next Page