python - django form.as_p doesnt render the form -
so here's form :
class secretnoteform(forms.form): note = forms.textarea()
here's view :
def index(request): if request.method == 'post': pass else: form = secretnoteform() return render(request, "notes/index.html", {"form" : form})
and html :
{% block content %} <form method="post">{% csrf_token %} {{ form.as_p }} <input type="submit" value="create"> </form> {% endblock %}
when go url shows me create button no form fields. doing wrong here ? can't seem figure out..
the correct way make textarea widget:
note = forms.charfield(widget=forms.textarea)
here more documentation: https://docs.djangoproject.com/en/dev/topics/forms/modelforms/
and include attributes that:
note = forms.charfield(widget=forms.textarea(attrs={'rows': 16,'cols': 25}))
Comments
Post a Comment