Django: Getting Started Transcripts
Chapter: Course conclusion
Lecture: Mapping URLs
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
A user types of URL into a browser which ultimately gets sent to Django Django then needs to map that URL into a function call or class
0:10
responsible for generating the web page for that URL. The system URLs.py file contains the master mapping of URLs to views.
0:19
It contains a variable named URL patterns, which is a list of path objects that map URLs.
0:24
There are several different kinds of things you can do when mapping a URL. You can use a built in view like the redirect view to serve a file directly
0:33
like a favion. You can also map a path to another URLs file either
0:38
through importing that module or using the include function to specify the name of it in text. In the first line of the light blue color here,
0:47
I've mapped a URL directly to a view. The say hello URL will get mapped to the say hello method inside of the primer.views module.
0:56
If you want to map the base URL. You map the empty string like in the third line of the blue code.
1:05
By default Django development server won't serve uploaded files which it calls media files.
1:11
You can get around this by using the static function from the static files module to mount the directory that contains your media files and serve them.
1:20
As this is a bad idea in production, I've added this mapping only in the situation where the settings configuration debug is set to true.