Django предотвращает перезагрузку страницы при отправке формы с помощью HttpResponseRedirect

Я хотел создать фрагмент моего сайта, чтобы он не заставлял всю страницу перезагружаться, когда кто-то заполняет форму. Я попробовал предыдущий вопрос: Django Как мне вставить данные без обновления или перезагрузки страницы

Я использовал HttpResponseRedirect, как было предложено в посте

В views.py:

def displayDict(request):
    m = ''
    ip = visitor_ip_address(request)
    try:
        m = ChatStream.objects.filter()
        last = m.latest()

        last_ss =  last.ss
        last_user =  last.user

        html_smallest_steps = markdown.markdown(last_ss)
        # html_user = markdown.markdown(last_user)
    except:
        html_ss = ''
        html_user = ''
    
    return render(HttpResponseRedirect, 'chatStream.html',
    {"chat": m, "html_ss": mark_safe(html_ss), "last_user": mark_safe(last_user)})

мой html:

{% for chat_stream in chat %}
    <p>
      {% comment %} {% if != forloop.last %}
        # Do something here
      {% endif %} {% endcomment %}
    {% if forloop.last %}
             
    {% else %}
        <b>ss:</b> <br> {{chat_stream.ss}} <br>
        <b>{{user}}:</b> <br> {{chat_stream.user}} <br>
    {% endif %}
    </p>
{% endfor %}
<form action="/send/" method = "post">{% csrf_token %}
    <input type="text" name="userMessage">
    <input type="submit" value="Send to ss bot">
</form>  
AttributeError: type object 'HttpResponseRedirect' has no attribute 'META'```

Более подробно вот полная ошибка:

Internal Server Error: /chattr/
Traceback (most recent call last):
  File "C:\Users\Kaij\Documents\djangoTests\django_tailwind_project\env\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\Kaij\Documents\djangoTests\django_tailwind_project\env\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\Kaij\Documents\chatSiteDjango\todoproject\todoapp\views.py", line 74, in displayDict   
    return render(HttpResponseRedirect, 'chatStream.html',
  File "C:\Users\Kaij\Documents\djangoTests\django_tailwind_project\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\Kaij\Documents\djangoTests\django_tailwind_project\env\lib\site-packages\django\template\loader.py", line 62, in render_to_string
    return template.render(context, request)        
  File "C:\Users\Kaij\Documents\djangoTests\django_tailwind_project\env\lib\site-packages\django\template\backends\django.py", line 61, in render
    return self.template.render(context)
  File "C:\Users\Kaij\Documents\djangoTests\django_tailwind_project\env\lib\site-packages\django\template\base.py", line 168, in render
    with context.bind_template(self):
  File "C:\Users\Kaij\AppData\Local\Programs\Python\Python39\lib\contextlib.py", line 119, in __enter__ 
    return next(self.gen)
  File "C:\Users\Kaij\Documents\djangoTests\django_tailwind_project\env\lib\site-packages\django\template\context.py", line 244, in bind_template
    updates.update(processor(self.request))
  File "C:\Users\Kaij\Documents\djangoTests\django_tailwind_project\env\lib\site-packages\django\template\context_processors.py", line 40, in debug
    if settings.DEBUG and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
AttributeError: type object 'HttpResponseRedirect' has no attribute 'META'
Вернуться на верх