From the course: Introduction to Django

Unlock this course with a free trial

Join today to access over 25,100 courses taught by industry experts.

URLs

URLs

- So now let's talk about URLs. We have looked already at defining your URLs in your urls.py, but you can actually do something called reversing a URL, which is getting a URL by its name. So given this simple URL's pattern, you are specifying the name profile, and this is inside of the user's app. So then in your Python files, if you wanted to get the URL, you could use the reverse function from Django URLs and then pass in the app name and then the name of the specific path, and this would return the URL path for it. Similarly, if you're in an HTML file and you want to get the path, then you can use the URL template tag here, pass in a string of the app, and then the specific name for the path, and that would give you this URL path, and then you could use that in your links, for example. So in this way, your URL config is specifying that this name points to this view function, and these paths that they're actually pointing to can change, and you can change them without worrying about…

Contents