Book Image

Learning Website Development with Django

Book Image

Learning Website Development with Django

Overview of this book

Table of Contents (18 chapters)
Learning Website Development with Django
Credits
About the Author
About the Reviewers
Preface
Index

Putting It All Together: Generating User Pages


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.

Creating the URL

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 urls.py 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 the underscore. The + sign after it causes the regular expression to match one or more...