[英]How can i make a form using django.contrib.comments.forms?
這是django.contrib.comments.forms的格式文件:
https://github.com/django/django/blob/master/django/contrib/comments/forms.py
我需要創建該形式的對象並在模板中使用它。 我不想在模板中手動制作html表單對象,我想重用該contrib.comments.forms。
我該怎么做?
這樣的事情。 根據您要如何處理表單數據,可能需要修改此代碼。
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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.