Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is r in Django urls.py?

The basic urls.py got statements like this,

(r'^home/$', homeview),

What is actually the r here?
What is the use of it?

like image 390
deena Avatar asked Feb 16 '15 12:02

deena


People also ask

What is urls py in Django?

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.

What is name in Django urls?

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 .

What is slug in Django urls?

A slug is a short label for something, containing only letters, numbers, underscores or hyphens. They're generally used in URLs."

What is path in URL Django?

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.


1 Answers

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' or R' prefix is present, backslashes are still used to quote the following character, but all backslashes are left in the string. For example, the string literal r"\n" consists of two characters: a backslash and a lowercase 'n'

So the r'\n' is equivalent of the '\\n'.

like image 54
catavaran Avatar answered Sep 18 '22 23:09

catavaran