i need to set rows and cols for a textarea in my HTML page from Django but it doesnt work.
I already put rows and cols in mine form
Views.py
class EditForm(forms.Form):
title = forms.CharField(widget=forms.TextInput(attrs={'name':'title'}))
body = forms.CharField(widget=forms.Textarea(attrs={'name':'body', 'rows':3, 'cols':5}))
def new(request):
return render(request,"encyclopedia/handlepage.html", {
"title": "CREATE NEW PAGE",
"edit": False,
"editpage": EditForm()
})
handlepage.html
{% extends "encyclopedia/layout.html" %}
{% block title %}
{{ title }}
{% endblock %}
{% block body %}
<h1>{{title}}</h1>
<a href="https://guides.github.com/features/mastering-markdown/">Markdown guides</a>
{% if edit %}
//Useless right now
{% else %}
<form method="POST" action="{% url 'save' %}">
<input type="submit" value="SAVE ENTRY"><br>
{% csrf_token %}
{{ editpage }}
</form>
{% endif %}
{% endblock %}
Then my page should have a small text area but it have the same size independent by its row and cols like this

I had the exact same issue and I think we are working on the same project because the screenshots look the same: was this Project 1 for CS50’s Web Programming with Python and JavaScript?
Anyway, I tried with
content = forms.CharField(widget=forms.Textarea(attrs={"rows":"5"}))
and it looked like it didn't work, but it was only because of a CSS property already applied that overrides the rows and columns attributes (as @AMG also suggested).
You can see this if you open your browser Inspector:

You just need to remove those two CSS properties for width and height to see the rows and columns attibutes apply.
I know that you have probably already solved this issue, but I'm posting this because I guess that fellow CS50 students may still need this answer in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With