python - Django forms not showing error when empty -


i have django forms, don't become red or show error when empty (they required). sort of sure of do.

views.py

def lout(request):     if request.user.is_authenticated():         context = {             "extendvar":"baseloggedin.html",         }     if request.user.is_authenticated()==false:         form=registerform(request.post or none)          if form.is_valid():             email = form.cleaned_data['email']             print ("yup")         elif form.is_valid()==false:             print ("nup")             print (form.errors)         print("eh")              context= {             "extendvar":"basenotloggedin.html",             "form":form,         } 

base.html:

{% extends extendvar %}  {% block title %}     {{ block.super }} lagro {% endblock %}  {% block fname %}     {{ form.fname }} {% endblock %}  {% block lname %}     {{ form.lname }} {% endblock %}  {% block email %}     {{ form.email }} {% endblock %}  {% block emailconfirm %}     {{ form.emailconfirm }} {% endblock %}  {% block password %}     {{ form.password }} {% endblock %} 

basenotloggedin.html

<form method="post" action="{% url 'try3' %}">   {% csrf_token %}   <div class="row row-buffer">       <div class="col-sm-6" style="padding-right:5px;" >         {% block fname %} {% endblock %}                         <!-- <input class="form-control" placeholder="first name" id="fname"> -->       </div>        <div class="col-sm-6" style="padding-left:5px;">         {% block lname %} {% endblock %}         <!-- <input class="form-control" placeholder="last name" id="lname"> -->       </div>      </div>     <div class="row row-buffer">       <div class="col-sm-12 form-group-lg">         {% block email %} {% endblock %}         <!-- <input class="form-control" placeholder="email" id="email"> -->        </div>     </div>      <div class="row row-buffer">       <div class="col-sm-12 form-group-lg">         {% block emailconfirm %} {% endblock %}       </div>     </div>      <div class="row row-buffer">       <div class="col-sm-12 form-group-lg">         {% block password %} {% endblock %}                         <!-- <input type="password" class="form-control" placeholder="password" id="password"> -->       </div>     </div>      <div class="row row-buffer">       <div class="col-sm-12 form-group-lg">         <button type = "submit" class="btn btn-success btn-lg" style="outline-width:0;">submit</button>       </div>     </div>   </form> 

forms.py

class registerform(forms.form):     fname = forms.charfield(max_length=256, label="", required=true, widget=forms.textinput(attrs={'class': 'form-control','placeholder': 'first name',}))     lname = forms.charfield(max_length=256, label="", required=true, widget=forms.textinput(attrs={'class': 'form-control','placeholder': 'last name',}))     email = forms.emailfield(max_length=256, label="", required=true, widget=forms.emailinput(attrs={'class': 'form-control','placeholder': 'email',}))     emailconfirm = forms.emailfield(max_length=256, label="", required=true, widget=forms.emailinput(attrs={'class': 'form-control','placeholder': 'confirm email',}))     password = forms.charfield(max_length=256, label="", required=true, widget=forms.passwordinput(attrs={'class': 'form-control','placeholder': 'password',})) 

it didn't show because didn't render errors in template. quoting django doc:

you need make sure take care of errors each field , errors form whole. note {{ form.non_field_errors }} @ top of form , template lookup errors on each field. using {{ form.name_of_field.errors }} displays list of form errors.

read django doc learn how render form errors in template.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -