Сайт Django работает на всех страницах, кроме нескольких

Я использую комбинацию python и django для загрузки сайта. Файл HTML home также присутствует в папке templates.

Я закодировал все части моего сайта так, как я обычно это делаю, и это сработало во всех случаях, кроме этого. Единственное приложение на моем сайте называется "Новости". Вот ошибка, которую я получил в терминале после нажатия на ссылку, которую дал мне python manage.py runserver.

Internal Server Error: /
Traceback (most recent call last):
  File "C:\Users\Mahsa\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner    
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mahsa\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "K:\Desktop 2.0\Python 6\irna_project\news\views.py", line 6, in home
    return render(request, "news/home.html", {"news", all_news})
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mahsa\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\shortcuts.py", line 24, in render
    content = loader.render_to_string(template_name, context, request, using=using)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mahsa\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\loader.py", line 62, in render_to_string
    return template.render(context, request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mahsa\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\backends\django.py", line 57, in render
    context = make_context(
              ^^^^^^^^^^^^^
  File "C:\Users\Mahsa\AppData\Local\Programs\Python\Python312\Lib\site-packages\django\template\context.py", line 286, in make_context
    raise TypeError(
TypeError: context must be a dict rather than set.
[28/Mar/2024 02:45:00] "GET / HTTP/1.1" 500 78799
Not Found: /favicon.ico
[28/Mar/2024 02:45:00] "GET /favicon.ico HTTP/1.1" 404 2334

Для получения дополнительной информации, вот основные файлы:

settings.py:

urls.py:

"""
URL configuration for irna project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/5.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from news import views

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.home),
] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)

home.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>IRNA</title>
</head>
<body>
   <h1>Welcome to IRNA</h1>
   {% for item in news %}
   <a href=""><h2>{{ item.title }}</h2></a>
   <h4>{{ item.date }}</h4>
   <img src="{{ item.image.url }}">
   <p>{{ item.content }}</p>
   <p>-----------------------------</p>
   {% endfor %}
</body>
</html>

views.py:

from django.shortcuts import render
from .models import News

def home(request):
    all_news = News.objects.all()
    return render(request, "news/home.html", {"news", all_news})

# Create your views here.

Я буду рад предоставить любые другие файлы, необходимые для решения этой проблемы.

Вернуться на верх