SHA256man
SHA256man

Reputation: 1

Trying to load a simple html in Django but it appears GET /homepage/ HTTP/1.1" 500 145

I did the Tutorial for the polling app on the official Django web page and everything worked out fine. Since I already have some HTML from my old website I wanted to reuse some of that. I decided to create an app called "homepage" for the main page you get when you visit the page (if this is bad practice, let me know). Since the main page is more or less just some introductory text and a navigation menu without any fancy functionality I did not create a DB (models) in this case. Furthermore I was sure that Django is able to simply deliver some plain static html without a database provided.

The urls.py in the hompage app folder looks like:

from django.urls import path
from . import views

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

and the view.py like this

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


def index(request):
    return HttpResponse("Hello, world. You're at the polls index.")

Everything works out fine. As soon as I try to load a html file (here a simple one just to check if it works) I get the error message. The new view.py looks like in the tutorial suggested:

def index(request):
    latest_question_list = 'Hallo'
    context = {'latest_question_list': latest_question_list}
    return render(request, 'homepage/index.html', context)

The folder structure is like suggested in the tutorial:

myproject_dir/myproject

myproject_dir/homepage/templates/hompage/index.html

The html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>My test page</title>
  </head>
  <body>
    <p>This is my page</p>
    <p>{{latest_question_list}}</p>
  </body>
</html>

Again, it works out fine with the poll app, which I have still working in the same project folder. This leaves me pretty confused and I'm looking forward to get some input.

Upvotes: 0

Views: 578

Answers (1)

Sunderam Dubey
Sunderam Dubey

Reputation: 8837

Set the default path in your project's urls.py in urlpatterns list.

from django.urls import path,include

urlpatterns=[
path('',include('homepage.urls'))
]

Then its next route will be decided through your app's urls.py that is homepage.

Upvotes: 1

Related Questions