Я пытаюсь следовать учебному пособию онлайн, и по какой-то причине я не могу заставить css правильно работать с моим файлом views.py и django 2.2
.когда я удаляю «My_context» из return render(request, 'blog/home.html', My_context)
и передаю что-то еще, например return render(request, 'blog/home.html', {'title': 'blah')
, это, кажется, работает просто отлично.
Я попытался перезагрузить сервер и очистить кэш страницы.Я новичок в django
и не уверен, что еще можно попробовать.
views.py
from django.shortcuts import render
posts = [
{
'author': 'xxxxx',
'title': 'Blog Post 1',
'Content': 'My First Post Content',
'date_posted': 'August 27, 2019'
},
{
'author': 'xxxxx',
'title': 'Blog Post 2',
'Content': 'My Second Post Content',
'date_posted': 'August 27, 2019'
}
]
# This function fails to load css correctly
def home(request):
My_context = {
'posts': posts
}
return render(request, 'blog/home.html', My_context)
#This function works fine
def about(request):
return render(request, 'blog/about.html', {'title': 'About'})
home.html
{% extends "blog/base.html" %}
{% block content %}
{% for post in posts %}
<h1>{{ post.title }}</h1>
<p>By {{ post.author }} on {{ post.date_posted }}</p>
<p>{{ post.Content }}</p>
{% endfor %}
{% endblock content %}
about.html
{% extends "blog/base.html" %}
{% block content %}
<h1>About Page</h1>
{% endblock content %}