Models.py
class ContactForm(models.Model):
name = models.CharField(max_length=50)
subject = models.CharField(max_length=200)
email = models.EmailField()
message = models.TextField()
def __str__(self):
return self.name
views.py
def contact(request):
if request.method == "POST":
name = request.POST.get('name')
subject = request.POST.get('subject')
email = request.POST.get('email')
message = request.POST.get('message')
ContactForm.objects.create(
name = name,
subject = subject,
email = email,
message = message
)
return render(
request,
'blog/contact.html',
{
'msg':'Details have been saved. We will get back to you.'
}
)
else:
return render(request, 'blog/contact.html')
contact. html
{% extends 'blog/base.html' %}
{% block content %}
<div class="container wrap mb-5" style="margin-top: 100px">
<h2 class="text">Contact Us</h2>
<form action="{% url 'contact' %}" method="POST">
{% csrf_token %}
<input type="text" placeholder="Enter Your Name" name="name">
<input type="text" placeholder="Subject" name="subject">
<input type="email" placeholder="Enter Your Email" name="email">
<input type="message" placeholder="Write Your Message" name="msg">
<input type="submit" value="Send" name="Submit">
</form>
{% if msg %}
<div class="alert alert-success">
{{ msg }}
</div>
{% endif %}
</div>
{% endblock %}
Произошла эта ошибка пока я нажимаю на кнопку отправки.
Показывает IntegrityError at /contact/ NOT NULL constraint failed: blog_contacts.message.