The basic urls.py got statements like this,
(r'^home/$', homeview),
What is actually the r
here?
What is the use of it?
In url.py, the most important thing is the "urlpatterns" tuple. It's where you define the mapping between URLs and views. A mapping is a tuple in URL patterns like − from django. conf. urls import patterns, include, url from django.
Django offers a way to name urls so it's easy to reference them in view methods and templates. The most basic technique to name Django urls is to add the name attribute to url definitions in urls.py .
A slug is a short label for something, containing only letters, numbers, underscores or hyphens. They're generally used in URLs."
The path function is contained with the django. urls module within the Django project code base. path is used for routing URLs to the appropriate view functions within a Django application using the URL dispatcher.
This is a prefix for raw strings (escape sequences are ignored) which is useful for sane regular expressions.
Excerpt from the docs:
When an
r'
orR'
prefix is present, backslashes are still used to quote the following character, but all backslashes are left in the string. For example, the string literalr"\n"
consists of two characters: a backslash and a lowercase'n'
So the r'\n'
is equivalent of the '\\n'
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With