mardi 10 mars 2020

Django templates won't load but HttpResponse will

I recently began learning django and have been running into some trouble and I can't figure out why.

My problem is quite simple: whenever I try to run my homepage with a template, it throws up a 404 error.

My file hierarchy is as such:

crm
 accounts
  templates
   accounts
    dashboard.html
  urls.py
  views.py
 crm
  urls.py

In crm/urls, I have

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


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

Then in accounts/urls, there is,

from django.urls import path
from . import views

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

And in views, I have

from django.shortcuts import render
from django.http import HttpResponse


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

My dashboard.html is just a basic html file with a title and h1, that's it.

Also, whenever I change

return render(request, 'accounts/dashboard.html')

to

return HttpResponse('home')

in my home function, it decides to show.




Aucun commentaire:

Enregistrer un commentaire