Reputation: 29
I am trying to render a template in django. I get this error when i connect to the site:
django.template.loaders.filesystem.Loader: path-to-azerty/templates/base.html (Source does not exist)
Here's my project directory structure:
azerty/
__init__.py
├── settings.py
├── templates
│ └── base.html
├── urls.py
├── views.py
└── wsgi.py
Here's my code:
// ulrs.py
from django.contrib import admin
from django.urls import path
from azerty import views
urlpatterns = [
path('', views.index),
path('admin/', admin.site.urls),
]
// settings.py
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',
],
},
},
]
//views.py
from django.shortcuts import render
def welcome(request):
return render(request, 'base.html')`
Upvotes: 1
Views: 376
Reputation: 309109
Your 'DIRS' setting is for a templates directory in your project directory (the one that contains manage.py).
If you want the templates to be on the inner directory (the one that contains settings.py, then you need to change it to:
os.path.join(BASE_DIR, 'azerty', 'templates')],
Another option that is sometimes used is to add azerty
to your INSTALLED_APPS
. Then the app loader will find the directory, and you can use 'DIRS': [],
Upvotes: 2