Пожалуйста, новичок в программировании, и я создаю веб-сайт с django 3.0.2 с учебным пособием django 1.10, но я столкнулся с ошибкой, я искал возможные решения, но не смог найти одно
вот вывод с терминала
Internal Server Error: /
Traceback (most recent call last):
File "C:\Users\LENOVO\Desktop\TGPB\env\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\LENOVO\Desktop\TGPB\env\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\LENOVO\Desktop\TGPB\env\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\LENOVO\Desktop\TGPB\blog\views.py", line 12, in post_list
return render(request, 'blog/post_list.html', {'posts: posts'})
File "C:\Users\LENOVO\Desktop\TGPB\env\lib\site-packages\django\shortcuts.py", line 19, in render
content = loader.render_to_string(template_name, context, request, using=using)
File "C:\Users\LENOVO\Desktop\TGPB\env\lib\site-packages\django\template\loader.py", line 62, in render_to_string
return template.render(context, request)
File "C:\Users\LENOVO\Desktop\TGPB\env\lib\site-packages\django\template\backends\django.py", line 59, in render
context = make_context(context, request, autoescape=self.backend.engine.autoescape)
File "C:\Users\LENOVO\Desktop\TGPB\env\lib\site-packages\django\template\context.py", line 270, in make_context
raise TypeError('context must be a dict rather than %s.' % context.__class__.__name__)
TypeError: context must be a dict rather than set.
Вот мой взгляд
from django.shortcuts import render
from .models import Author, Tag, Category, Post
def index(request):
return HttpResponse("Hello Django")
#View function to display list of posts
def post_list(request):
posts = Post.objects.all()
return render(request, 'blog/post_list.html', {'posts: posts'})
и мой шаблон post_list
{% extends "blog/base.html" %}
{% block title %}
Blogg - {{ block.super }}
{% endblock %}
{% block content %}
<div class="content">
<div class="section-inner clearfix">
{% for post in posts %}
<h3>
<a href="http://127.0.0.1:8000/{{ post.pk }}/">{{ post.title|capfirst }}</a>
</h3>
<p class="post-info">
<span>Date: {{ post.pub_date }} </span> |
<span>Category: <a href="http://127.0.0.1:8000/category/{{ post.category.slug }}">{{ post.category.name }}</a></span> |
<span>Tag:
{% for tag in post.tags.all %}
<a href="http://127.0.0.1:8000/tag/{{ tag.slug }}">{{ tag.name }}</a>
{% empty %}
None
{% endfor %}
</span>
</p>
{% empty %}
<p>There are no posts</p>
{% endfor %}
</div>
</div>
{% endblock %}