Creating a django master template

0

Hello my question is this, I am following this tutorial link and leave the point where you go to the templates directory and create an html file but do not know or there is not a directory of that type, check the settings.py and do not know if that's where adds a directory (I guess that by previous versions of django I did not do it like in the tutorial or skipped that part)

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
            ],
        },
    },
]

is where I should indicate a directory to read the templates and if that were the case: Is that directory created in an app or in the project folder?

    
asked by Naoto 01.11.2017 в 20:08
source

1 answer

0

It is necessary that you create a folder called templates within your application. Within that folder you can create all your templates, which are called from the methods of the view (file views.py ).

The slightly longer explanation is that this is implicitly configured in an object within the TEMPLATES array in the settings.py file. The property BACKEND of that object defines the template engine to be used, (in this case django.template.backends.django.DjangoTemplates ) and the Boolean property APP_DIRS tells the engine whether or not it should look for templates files within the installed applications. Each backend has a name defined for the subdirectory within the applications in which it will search, and in the case of the DjangoTemplates backend, the name is templates . That's why you should create that folder inside the app and put the template html files there. More details on this link

    
answered by 01.11.2017 / 20:53
source