Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does include() in urls.py do in django?

I am new to django. I came across the include() method. I read the documentation regarding it. But couldn't understand it as it lacked suitable examples. I am again rewriting this question in a proper way so that it doesn't sound baseless. Can someone please help me out by giving me a suitable example regarding the scenario in which the include() method becomes handy?

like image 721
Mangu Singh Rajpurohit Avatar asked Jul 21 '15 07:07

Mangu Singh Rajpurohit


People also ask

What is include () in Django?

The include tag allows you include a template inside the current template. This is useful when you have a block of content that are the same for many pages.

What is use of include function in urls py file in Django?

From django document, include() function was described as follows. Whenever Django encounters include(), it chops off whatever part of the URL matched up to that point and sends the remaining string to the included URLconf for further processing.

When should one use the include () in Django?

include tag loads a template and renders it with the current context. This is a way of “including” other templates within a template. The template name can either be a variable or a hard-coded (quoted) string, in either single or double quotes.

What does the Django urls reverse () function do?

reverse_lazy()providing a reversed URL as the url attribute of a generic class-based view. providing a reversed URL to a decorator (such as the login_url argument for the django.


1 Answers

include() adds urls from your app directory's urls.py to the main urls.py (in memory). This keeps the main urls.py from getting too big to read.

see https://docs.djangoproject.com/en/2.2/topics/http/urls/

The Including Other URLConfs section.

like image 50
Tony Dare Avatar answered Oct 03 '22 05:10

Tony Dare