-
Notifications
You must be signed in to change notification settings - Fork 0
urls.py (page)
There are three different URL patterns specified in the url.py file:
urlpatterns = [
url(r'^admin/', include(admin.site.urls), name='admin'),
url(r'^markdown/', include('django_markdown.urls')),
url(r'^', include('wiki.urls'), name='wiki'),
]
Every URL-pattern are wrapped with url. Then it has three (or two) parameters.
The first parameter is the pattern expressed in a regular expression (think of it like a pattern that a word or sentence may or may not match).
The second parameter is the URLs to include. Since this is not really an app, just a empty shell that includes all the other apps we use, it does not have own URLs. It just include URLs form other apps.
The third (optional) parameter is a name. This can be used when we want use the URL in our site. For example, if we want to include the admin URL somewhere (like a link to the admin page), instead of writing "/admin" (which is the URL to the admin page), we can write something like {% url 'amdin' %}
, and it will be replaced by the actual URL to the admin page. This is useful incase the admin URL suddenly change, for example from "/admin" to "/root". Then we can simply change r'^admin/'
to r'^root/'
, and all the URLs in our site pointing to the admin page would still be correct.
This is just the admin URLs. This is included by default in all Django projects, and are made by the Django crew. So any URL that starts with "admin/" (like "/admin/page/1/edit") will be sent to "admin.site.urls" (a file called urls.py inside a package called 'site' in the admin app), and will try to match any of the URLs specified there.
This is the URLs for markdown. I don't think we really use these URLs, as they are for some features of the django_markdown app that we do not currently use.
This patteren matches every URL, or, everything that starts with '' (an empty string). You might think that this will screw up our other patterns, since they also would match this. Fortunately this is not the case. The URL always chooses the pattern that matches "best", or most of the URL (often referred to as the most specific pattern). And something that starts with "admin/" will therefor choose the admin URLs, since that is a more specific, or "better", match. So, in shorts, everything that do not start with either "admin/" nor "markdown/" will match this pattern, and pass it on to the wikis URL patterns (located in urls.py inside the wiki app folder).