Ошибка 405 при отправке формы Django
у меня возникает ошибка 405 при передачи POST. А именно:
Method Not Allowed (POST): /
Method Not Allowed: /
[15/Feb/2022 20:41:54] "POST / HTTP/1.1" 405 0
Это ошибка возникает при отправление формы со страницы браузера. С другим html кодом который я создал до этого работало, но после того как я создал страницу в Nicepage и заменил старую, форма перестала отправляться , и выдаёт 405. На данном этапе изучение Django я не знаю как решить эту проблему.
index.html (Секция с формой):
<section class="u-align-center u-clearfix u-section-8" >
<div class="u-clearfix u-sheet u-sheet-1">
<h2 class="u-text u-text-default u-text-1">Коментарии</h2>
<div class="u-form u-form-1">
<form action="{% url 'home' %}" method="post" class="u-clearfix u-form-spacing-10 u-form-vertical u-inner-form" style="padding: 10px" enctype="multipart/form-data" source="custom" name="form" >
{% csrf_token %}
<div class="u-form-group u-form-name u-label-none">
{{forma.author}}
</div>
<div class="u-form-group u-form-message u-label-none">
{{ forma.content }}
{{ forma.is_published }}
{{ forma.time_create}}
</div>
<div class="u-align-left u-form-group u-form-submit">
<button type="submit" value = 'Submit' class="u-btn u-btn-submit u-button-style">Отправить</button>
</div>
</form>
</div>
</div>
</section>
forms.py:
from django import forms
from .models import *
class AddCommentForm(forms.ModelForm):
class Meta:
model = Comment
fields = ('author', 'content', 'is_published')
widgets = {
'author': forms.TextInput( attrs={'type':"text", 'placeholder':"Введите ник", 'id':"name-3b9a" ,'name':"name", 'class':"u-border-1 u-border-grey-30 u-input u-input-rectangle u-white"}),
'content': forms.Textarea( attrs={'placeholder':"Введите текст", 'rows':4, 'cols':50, 'id':"message-3b9a" ,'name':"message", 'class':"u-border-1 u-border-grey-30 u-input u-input-rectangle u-white"})}
urls.py:
from django.contrib import admin
from django.urls import include, path
from .views import *
from main.views import *
urlpatterns = [
path('', MainHome.as_view(), name='home'),
]
view.py:
class MainHome(DataMixin, ListView):
model = Changes
context_object_name = 'log'
template_name = 'main/index.html'
def get_context_data(self,*, object_list=None, **kwargs):
context = super().get_context_data(**kwargs)
c_def = self.get_user_context(title='Главная Страница')
return dict(list(context.items()) + list(c_def.items()))
utils.py:
from main.forms import AddCommentForm
from .models import *
from django.db.models import Count
class DataMixin:
def get_user_context(self, **kwargs):
context = kwargs
forma = AddCommentForm
log = Changes.objects.all()
com = Comment.objects.all()
context['forma'] = forma
context['com'] = com
context['log'] = log
return context
model.py:
from django.db import models
class Changes(models.Model):
title = models.CharField(max_length=255, verbose_name="Заголовок")
content = models.TextField(blank = True)
time_create = models.DateTimeField(auto_now_add=True)
class Meta:
verbose_name = 'Изменения'
verbose_name_plural = 'Изменения'
ordering = ['-time_create']
def __str__(self):
return self.title
class Comment(models.Model):
author = models.CharField(max_length=20)
content = models.TextField(blank = True)
time_create = models.DateTimeField(auto_now_add=True)
is_published = models.BooleanField(default=True)
class Meta:
verbose_name = 'Комментарии'
verbose_name_plural = 'Комментарии'
ordering = ['-time_create']
def __str__(self):
return self.author