web page blank

39 views
Skip to first unread message

Delvin Alexander

unread,
Feb 2, 2022, 12:59:28 AM2/2/22
to Django users
Hello everyone,

I am currently following a django tutorial regarding applications. I have followed through completely but for some reason, when I run server, i incur no errors but the web page is blank. Why would this be?

Here is what is not displayed:

from my Home.html file:
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    {% for post in posts %}
        <h1>{{ post.title }}</h1>
        <p>By {{ post.author }} on {{ post.date_posted}}</p>
        <p>{{ post.content }}</p>
    {% endfor %}

</body>
</html>

from my views.py file:
from django.shortcuts import render

post = [
    {
        'author': 'CoreyMS',
        'title': 'Blog Post',
        'content': 'First Post Content',
        'date_posted': 'August 27, 2018'
    },
    {
        'author': 'Jane Doe',
        'title': 'Blog Post 2',
        'content': 'Second Post Content',
        'date_posted': 'August 28, 2018'
    }
]

def home(request):
    context = {
        'post': post
    }
    return render(request, 'blog/home.html', context)

def about(request):
    return render(request, 'blog/about.html')

My urls.py:
from django.urls import path
from . import views

urlpatterns = [
    path('', views.home, name='blog-home'),
    path('about/', views.about, name='blog-about'),
]
     

Sebastian Jung

unread,
Feb 2, 2022, 2:08:16 AM2/2/22
to django...@googlegroups.com
Hello,

Please try:

context = {
        'posts': post
    }

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e9b557a6-403b-46ce-bc18-8d19b0091f2an%40googlegroups.com.

Dev femibadmus

unread,
Feb 2, 2022, 3:23:46 AM2/2/22
to django...@googlegroups.com
Is it working fine for you?


If not url blog/home.html?

kka kar

unread,
Feb 2, 2022, 8:37:44 AM2/2/22
to Django users
I recreated the project and changed the view function to the below, and it now works fine for me:

def home(request):
context = {
'posts': post
}
return render(request, 'home.html', context)

Alex Dénho

unread,
Feb 4, 2022, 5:02:54 PM2/4/22
to django...@googlegroups.com

Delvin Alexander

unread,
Feb 7, 2022, 9:50:04 PM2/7/22
to django...@googlegroups.com
it  is now, thank you for your help!

You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/OKU-v7eWPtc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAD9bWYzcLeS5HbKQvpa3v%3Drt015_Pufd8BVMe7R_U0OaGZO09g%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages