Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to fix this error: Template Does Not Exist ? Django

urls.py

from django.urls import path

from . import views

urlpatterns = [ 
    path('',views.home, name='home')
    
]

another urls.py

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('', include('subokLang.urls')),
    path('admin/', admin.site.urls),
]

settings.py – templates

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / 'tryingDjango/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
from django.http import HttpResponse

def home(request):
    return render(request, 'templates/home.html')

I am stuck here, tried changing many already, still won’t work, the 500(Template does not exist), what is the right code?

Thanks in advance!

>Solution :

In your settings.py file:

inside TEMPLATES, just add this:

[os.path.join(BASE_DIR, 'templates')]

Ex:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')], #Added here
        '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',
            ]
        },
    },
]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading