Django Base Page is blank

88 Views Asked by At

I'm following this tutorial to learn Django and I've followed part 4 as in the video, but when I reload my page, it's always blank. I've looked at other posts that were also experiencing a blank page, but they don't address my issue and are very old.

Some more info: I'm using Django 4.1.4, all the files are appropriately saved and named like in the video and there are no errors in the terminal

This is my views.py:

from django.shortcuts import render
from django.http import HttpResponse
from .models import ToDoList, Item
# Create your views here.

def index(response, id):
    ls = ToDoList.objects.get(id=id)
    return render(response, 'main/base.html', {})

def home(response):
    return render(response, 'main/home.html', {})

base.html:

<html>  
<head>
    
    <title> My Website </title>
</head>

<body>
    
    <p> Base Template</p>
    <h1> HELLO </h1>
    
</body>
</html> 

home.html:

{% extends 'main/base.html' %}

I don't know if this issue is caused by a mistake I'm not finding or a version error.

2

This is a picture of my folders.

1

There are 1 best solutions below

1
On

urls.py (in "main" folder) must contain:

from django.urls import path
from . import views

urlpatterns = [
    path("<int:id>", views.index, name="index"),
    path("", views.home, name="home"),
]

but urls.py (in "mysite" folder) must contain:

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

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

Also base.html and home.html must be in main->templates->main folder Dont forget to add this in mysite->settings

INSTALLED_APPS = [
    ...
    'main.apps.MainConfig', #this string
]

After this make python manage.py runserver and open in browser http://127.0.0.1:8000/ But this is a blind parsing, if you wrote what error you have in the terminal, it would be easier to figure out what the specific reason is