After the project is successfully created, now we shall create two folders static
and template
, for storing the static files and django templates respectively. These folders should be created in the root folder where the manage.py
file is present.
After creating the static and templates folder, these needs to be linked with the project. This can be done by modifying the settings.py
file of the project.
In the first stage we shall import the os
module in the start of our settings.py
file :
import os
The templates
folder can be linked by editing the TEMPLATES
configuration in the settings.py
file as follows :
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "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',
],
},
},
]
Similarly for linking the static
folder, this line of code can be added at the bottom of the file :
STATIC_URL = '/static/'
STATICFILES_DIRS=[
os.path.join(BASE_DIR, "static"),
]
After these changes, the templates
and static
folder will be configured successfully.