• Ask a Question
  • Create a Poll
150
    Ask a Question
    Cancel
    150
    More answer You can create 5 answer(s).
      Ask a Poll
      Cancel

      How to do styling in templates, styling on my forms is not working in django

      Here is my forms.py file where addmanagerform function is defined

      from django import forms from bus_booking.models import Manager, Staff, Bus, Terminal, Schedule     class AddManagerForm(forms.Form):     email=forms.EmailField(label="Email",max_length=50,widget=forms.EmailInput(attrs={'placeholder':'Enter your email','class':'form-control'}))     password=forms.CharField(label="Password",min_length=8,widget=forms.PasswordInput(attrs={'placeholder':'Enter your password',"class":"form-control"}))     name=forms.CharField(label="Name",min_length=4,max_length=20,widget=forms.TextInput(attrs={'placeholder':'Enter your name',"class":"form-control"}))     username=forms.CharField(label="Username",min_length=4,max_length=10,widget=forms.TextInput(attrs={'placeholder':'Enter a unique username',"class":"form-control"}))     gender_choice=(         ("Male","Male"),         ("Female","Female")     )      cnic=forms.CharField(label="Cnic",max_length=13,min_length=13,widget=forms.TextInput(attrs={'placeholder':'xxxxxxxxxxxxx',"class":"form-control"}))     gender=forms.ChoiceField(label="Gender",choices=gender_choice,widget=forms.Select(attrs={'placeholder':'Select',"class":"form-control"}))     address=forms.CharField(label="Address",max_length=200,widget=forms.TextInput(attrs={'placeholder':'Enter your address',"class":"form-control"}))     salary=forms.IntegerField(label="Salary",widget=forms.NumberInput(attrs={'placeholder':'b/w 5000 - 1000000',"class":"form-control"}))     date_of_birth=forms.DateField(label="DOB",widget=DateInput(attrs={'placeholder':'Enter your date of birth',"class":"form-control"}))     contact_number=forms.CharField(label="Contact",max_length=10,min_length=10,widget=forms.TextInput(attrs={'placeholder':'+92xxxxxxxxxx (enter 10 digits)',"class":"form-control"})) 

      Here is form.html:

       <form role="form" action="{{ action_path }}" method="post" enctype="multipart/form-data">                   {% csrf_token %}                 <div class="card-body">                      {% for field in form %}                   <div class="form-group">                       {{ field.errors }}                       {{ field.label_tag }}                       {{ field }}                   </div>                     {% endfor %}                     <div class="form-group">                       {% if messages %}                         {% for message in messages %}                         {% if message.tags == 'error' %}                         <div class="alert alert-danger" style="margin-top:10px">{{ message }}</div>                         {% endif %}                         {% if message.tags == 'success' %}                         <div class="alert alert-success" style="margin-top:10px">{{ message }}</div>                         {% endif %}                         {% endfor %}                       {% endif %}                     </div>                  </div>                 <!-- /.card-body -->                  <div class="card-footer">                   <button type="submit" class="btn btn-primary btn-block">{{ button_text }}</button>                 </div>               </form>

      But my styling on forms is not working, it shows me form like:

      enter image description here

      Where i am doing mistake that styling is not working, is there any issue of importing some thing?

      1 Answers

      Have you linked the necessary stylesheets like bootstrap in html file?

      Answered by Faustinorubenmaureen on July 16, 2020..