This chapter has covered a lot of material. It has introduced the concepts of views, models, and templates. In the final section, we will write another view and make use of all the information that we have learned so far. This view will display a list of all the bookmarks that belong to a certain user.
The URL of this view will have the form user/username
, where username is the owner of the bookmarks that we want to see. This URL is different from the first URL that we added because it contains a dynamic portion. So we will have to employ the power of regular expressions in order to express this URL. Open the urls.py
file and edit it so that the URL table looks like this:
urlpatterns = patterns('',
(r'^$', main_page),
(r'^user/(\w+)/$', user_page),
)
The pattern here looks more complicated than the first one. \w
means an alphanumeric character or an underscore. The +
sign after it causes the regular expression to match one or...