0

I want to increase width of dropdown field in Django form, I tried both inline CSS as well as widgets, below is code I have tried

index.html

{% extends "base_generic.html" %}
 {% block content %}
  <form action = "" method = "post">
    {% csrf_token %}
      **<center>Product: <h6 style="width: 350px;">{{ form.product }}</h6></center>** 
      <br>
        <center>Rules: {{ form.rule }}</center>
    <input type="submit" value=Compute>
  </form>
{% endblock %}

forms.py

from django import forms

PRODUCTS = (
    ('hp','HP'),
    ('wipro', 'WIPRO'),
)

class InputForm(forms.Form):
    class Meta:
        **widgets = {'product': forms.Select(attrs={'style': 'width:200px'})}**

    product = forms.ChoiceField(choices=PRODUCTS)
    rule = forms.CharField(widget= forms.Textarea, label="Rules")

Click to see output

How can I achieve this?

1 Answers1

0

Try to Pip install "django-widget-tweaks" as this will enable you to use custom css easily.

claver
  • 32
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 01 '23 at 22:37