[英]django form.as_p doesnt render the form
So here's my form : 所以这是我的表格:
class SecretNoteForm(forms.Form):
note = forms.Textarea()
Here's my view : 这是我的观点:
def index(request):
if request.method == 'POST':
pass
else:
form = SecretNoteForm()
return render(request, "notes/index.html", {"form" : form})
and my html : 和我的HTML:
{% block content %}
<form method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Create">
</form>
{% endblock %}
When I go to the url it only shows me Create button but no form fields. 当我转到网址时,它只显示我创建按钮但没有表单字段。 What am I doing wrong here ?
我在这做错了什么? I can't seem to figure that out..
我似乎无法弄明白......
The correct way to make a TextArea is with a widget: 制作TextArea的正确方法是使用小部件:
note = forms.CharField(widget=forms.Textarea)
Here is more documentation: https://docs.djangoproject.com/en/dev/topics/forms/modelforms/ 以下是更多文档: https : //docs.djangoproject.com/en/dev/topics/forms/modelforms/
and include attributes like that: 并包括这样的属性:
note = forms.CharField(widget=forms.Textarea(attrs={'rows': 16,'cols': 25}))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.