How to configure fields in Django forms.Form?

Viewed 88

I'm learning Django and web dev and having difficulty configuring the fields in Django forms.Form so that they come out correctly. Below is my code:

Even if I adjust my attrs rows and cols in forms.Textarea it doesn't make any difference. Also, it doesn't seem to matter what I put in CSS the output is still the same.

class NewPageForm(forms.Form):
    title = forms.CharField(label="Title", max_length=100, widget=forms.TextInput)
    content = forms.CharField(label="Content", widget=forms.Textarea(attrs{"rows":3,"cols":10}))

My html:

{% block body %}    
    <div class="form">
        <form action="{% url 'create' %}" method="post">
            {% csrf_token %}
            {{ form.as_p }}
            <input type = submit>
        </form>
    </div>
{% endblock %}

What it looks like:

screenshot

Please advise.

1 Answers

You may try:

content = forms.CharField(label=False, widget=forms.Textarea(attrs={'rows': 3}))

or even add a CSS class to customize it:

content = forms.CharField(label=False, widget=forms.Textarea(attrs={'class': 'form-control', 'rows': 3}))
Related