I'm using Django for a project, but I came across a question.
In my file settings.py
I have the following configuration of templates :
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'tests/templates'),
os.path.join(BASE_DIR, 'core/templates')
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
And the following method in my file view.py
Django uses the MTV model, so the view is equivalent to the controller in the MVC model
def index(request):
template = loader.get_template('create.html')
return HttpResponse(template.render())
I have two directories, the tests / templates and the core / templates, when I use the get_template
method it takes from any of the directories.
If you create a file named "create.html" in both directories, it takes what is inside my "application" where the "view.py" file is located, if I remove the "create.html" file from "tests ", it automatically takes what is in the" core "folder.
Django separates the code into "applications", which functions as a sort of module.
I would like to define which folder (application) my template comes from.
UPDATE
I found in the documentation a form, but I found it redundant, to put the same application name inside the folder template, if there already exists the separation of the application, why would create another separation within template? Is there any way to use the application name itself for this?