Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 40867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:05:27+00:00 2026-05-10T15:05:27+00:00

How can I change the width of a textarea form element if I used

  • 0

How can I change the width of a textarea form element if I used ModelForm to create it?

Here is my product class:

class ProductForm(ModelForm):     long_desc = forms.CharField(widget=forms.Textarea)     short_desc = forms.CharField(widget=forms.Textarea)     class Meta:         model = Product 

And the template code…

{% for f in form %}     {{ f.name }}:{{ f }} {% endfor %} 

f is the actual form element…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T15:05:27+00:00Added an answer on May 10, 2026 at 3:05 pm

    The easiest way for your use case is to use CSS. It’s a language meant for defining presentation. Look at the code generated by form, take note of the ids for fields that interest you, and change appearance of these fields through CSS.

    Example for long_desc field in your ProductForm (when your form does not have a custom prefix):

    #id_long_desc {     width: 300px;     height: 200px; } 

    Second approach is to pass the attrs keyword to your widget constructor.

    class ProductForm(ModelForm):     long_desc = forms.CharField(widget=forms.Textarea(attrs={'cols': 10, 'rows': 20}))     short_desc = forms.CharField(widget=forms.Textarea)     class Meta:         model = Product 

    It’s described in Django documentation.

    Third approach is to leave the nice declarative interface of newforms for a while and set your widget attributes in custom constructor.

    class ProductForm(ModelForm):     long_desc = forms.CharField(widget=forms.Textarea)     short_desc = forms.CharField(widget=forms.Textarea)     class Meta:         model = Product      # Edit by bryan     def __init__(self, *args, **kwargs):         super(ProductForm, self).__init__(*args, **kwargs) # Call to ModelForm constructor         self.fields['long_desc'].widget.attrs['cols'] = 10         self.fields['long_desc'].widget.attrs['rows'] = 20 

    This approach has the following advantages:

    • You can define widget attributes for fields that are generated automatically from your model without redefining whole fields.
    • It doesn’t depend on the prefix of your form.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a textarea form where you can change your description and like
I can't seem to change width in IE7 http://jsfiddle.net/Mkb9n/1/ You can see that all
How can I change for example default width and height for buttons, etc?
I am a little perplexed here with the actions of WPF. I can change
how can I change a form's action with prototype ? I've seen plenty of
By default Zend Form Text elements don't have a width specified. Textarea elements have
When I create a html form like this: $form = new Zend_Form(); $form->setMethod('post'); $form2->addElement('textarea',
How i can change the color with gradient??? I have this now,but is different
I can change the irb prompt mode with irb --prompt prompt-mode I can see
I can change SQL at runtime. Can I do the same with LINQ ?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.