Hello, I hope you can help me with this problem of trying to load the template
which, even after following different tutorials and steps, always gives the same error.
Here’s my project structure
DjangoProject (Python Folder)
djangoproject
djangoproject(settings.py, urls.py, etc...)
myapp(migrations folder, urls.py, views.py, etc...)
templates(home.html)
djangoproject/settings.py
ROOT_URLCONF = 'djangoproject.urls'
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',
],
},
},
]
djangoproject/urls.py
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path("myapp/", include("myapp.urls")),
path("admin/", admin.site.urls),
]
myapp/view.py
from django.shortcuts import render
from django.http import HttpResponse, request
# Create your views here.
def mainpage_view(*args, **kwargs):
# return HttpResponse("<h1>Hello World Telmo</h1>")
return render(request, "home.html", {})
def contact_view(*args, **kwargs):
return HttpResponse("<h1>Contact Page</h1>")
def about_view(*args, **kwargs):
return HttpResponse("<h1>About Page</h1>")
def social_view(*args, **kwargs):
return HttpResponse("<h1>Social Page</h1>")
myapp/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.mainpage_view, name="home"),
path('contact/', views.contact_view),
path('about/', views.about_view),
path('social/', views.social_view),
]
The error message when I run the server:
TemplateDoesNotExist at /myapp/home.html
Request Method: | GET |
---|---|
Request URL: | http://127.0.0.1:8000/myapp/ |
Django Version: | 4.2.7 |
Exception Type: | TemplateDoesNotExist |
Exception Value: | home.html |
Exception Location: | C:\Users\telmo\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\template\loader.py, line 19, in get_template |
Raised during: | myapp.views.mainpage_view |
django.template.loaders.filesystem.Loader
: C:\Users\telmo\OneDrive\Ambiente de Trabalho\DjangoProject\templates\home.html (Source does not exist)
Terminal error shows me this:
Not Found: /myapp/4f64eaa44708eacdfb67703150ce5f05.jpg