Привет, создал модель форми, саму форму и обработку данных во views.py, хочу ее отобразить на странице c помощью html шаблона в блоке {{ form }} но ничего не происходит.
Модель:
class Comment(models.Model):
product = models.ForeignKey('Product', on_delete=models.CASCADE, related_name='comments', db_column=None)
name = models.CharField(max_length=50)
email = models.EmailField(max_length=50)
text = models.TextField()
date_pub = models.DateTimeField(auto_now_add=True)
approved_comment = models.BooleanField(default=False)
views:
def comment(request, pk):
post = get_object_or_404(Product, pk=pk)
if request.method == 'POST':
form = CommentForm(request.POST)
if form.is_valid():
comm = form.save(commit=False)
comm.post = post
comm.save()
else:
form = CommentForm()
return render(request, 'App/Product_information.html', {'post': post, 'form': form})
forms:
from django.forms import ModelForm
from .models import Comment
class CommentForm(ModelForm):
class Meta:
model = Comment
fields = ('name', 'text', 'email')
Шаблон:
{% extends 'base.html' %}
{% block content %}
<form action="" method="post" class="post-form">
{% csrf_token %}
{{ form }}
</form>
{% endblock %}