Reputation: 12466
This is the form file of django.contrib.comments.forms:
https://github.com/django/django/blob/master/django/contrib/comments/forms.py
I need to create an object of that form and use it in template. I don't want to make html form object manually in templates, I want to reuse that contrib.comments.forms.
How can i do it?
Upvotes: 2
Views: 166
Reputation: 4751
Something like this. May be need to modify this code depending on how do you want to process form data.
from django.contrib.comments.forms import CommentForm
# views.py
dev my_view(request):
my_obj = MyModel.objects.get(id=1)
form = CommentForm(my_obj)
return render(request, 'comment-template.html', {'form': form})
# comment_template.html
<form action="{% comment_form_target %}" method="post">
{% csrf token %}
{{ form.as_p }}
<input type="submit">
</form>
Upvotes: 1