'Cant render HTML file on Django

Django 4.0.3 and Python 3.10.2

I cant render a html file on my project. What am i missing? Main parts of code below.

Settings.py at INSTALLED_APPS:

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app1',
]

Settings.py at TEMPLATES:

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    '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',
        ],
    },
    # 'DIRS': [r'project1\app1\templates\app1'],        
    'DIRS': [os.path.join(BASE_DIR, 'templates')],
},
]

Project-Urls:

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

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('app1.urls')), # main will be the name of your app
]

App1-Urls:

from django.urls import path
from . import views

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

Views:

def simple_function(request):
   print("Print executes correctly, but the render doesn't")
   return render(request, r'project1\app1\templates\app1\home.html')

Html file path: app1/templates/app1/home.html

Github of this project

Had to post this bunch of information to clarify.



Solution 1:[1]

instead of

return render(request, r'project1\app1\templates\app1\home.html')

try to write

return render(request, 'app1/home.html')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JashOFHop