簡體   English   中英

django form.as_p不會呈現表單

[英]django form.as_p doesnt render the form

所以這是我的表格:

class SecretNoteForm(forms.Form):
    note = forms.Textarea()

這是我的觀點:

def index(request):
    if request.method == 'POST':
        pass
    else:
        form = SecretNoteForm()

    return render(request, "notes/index.html", {"form" : form})

和我的HTML:

{% block content %}
<form method="post">{% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="Create">
</form>
{% endblock %}

當我轉到網址時,它只顯示我創建按鈕但沒有表單字段。 我在這做錯了什么? 我似乎無法弄明白......

制作TextArea的正確方法是使用小部件:

note = forms.CharField(widget=forms.Textarea)

以下是更多文檔: https//docs.djangoproject.com/en/dev/topics/forms/modelforms/

並包括這樣的屬性:

note = forms.CharField(widget=forms.Textarea(attrs={'rows': 16,'cols': 25}))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM