Skip to content
Boye Borg edited this page Jul 30, 2015 · 2 revisions

This file specifies all the valid URL patterns in the wiki app, and map them with a view function located in the view.py file.

urlpatterns = [
    url(r'^$', 'wiki.views.home_page', name='home_page'),
    url(r'^login/$', 'wiki.views.login_user', name='login_user'),
    url(r'^logout/$', 'wiki.views.logout_user', name='logout_user'),
    url(r'^view/(?P<slug>[^\.]+).html$', 'wiki.views.view_page', name='view_page'),
    url(r'^edit/(?P<slug>[^\.]+).html$', 'wiki.views.edit_page', name='edit_page'),
    url(r'^save/(?P<slug>[^\.]+).html$', 'wiki.views.save_page', name='save_page'),
    url(r'^history/(?P<slug>[^\.]+).html$', 'wiki.views.page_history', name='page_history'),
    url(r'^history/(?P<slug>[^\.]+)/(?P<version_id>[0-9]+)$', 'wiki.views.page_change', name='page_change'),
    url(r'^search/', include('haystack.urls')),
    url(r'^delete/$', 'wiki.views.delete_page', name='delete_page'),
]

The first parameter of each URL defines the [regular expression][1] of the pattern. A more specific match will always be prioritised over a less specific match. Some of the regular expressions have something like "(?P...)". This will pass the matched content inside the parentheses as a argument in the view function with the name "slug".

The second parameter is either the view function or a reference to another urls.py-file withe more URLs.

The last optional parameter is the name of the URL pattern. This can be used when referencing the URL inside our project. Eg. {% url 'view_page' 'start' %} would yield "view/start.html".

Clone this wiki locally