[Fixed]-Input text field do not show on browser – Django

1👍

Okay so Django doesn’t allows you to add attrs for form fields in case of forms.Form

Either you need to use ModelForm. Something like this:

from django import forms

class MyForm(forms.ModelForm):
    class Meta:
        model = MyModel
        widgets = {
          'text': forms.Textarea(attrs={'rows':1, 'cols':85}),
        }

But for your use case, I would recommend using https://pypi.python.org/pypi/django-widget-tweaks package like this in your template:

So firstly pip install django-widget-tweaks

Now add django-widget-tweaks in installed_apps in settings.py like this:

INSTALLED_APPS = (
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'widget_tweaks',
)

Now use them ion your templates like this:

{% load widget_tweaks %}
...
{{ form.text|attr:"rows:1"|attr:"cols:85" }}

See this -> How can i set the size of rows , columns in textField in Django Models

Leave a comment