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

  • SEARCH
  • Home
  • 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 334947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:06:11+00:00 2026-05-12T10:06:11+00:00

now im learning to validate form, all is working, im showing the erros of

  • 0

now im learning to validate form, “all” is working, im showing the erros of empty fields, but i have 2 questions:

  1. how ill show the value in the filled fields when there are errors in another fields?, like <input ... value= {{ value }} > the problem is that my fields are not html forms fields.
  2. how ill show the error exactly over the empty fields?

how i have this:

form.py

class NuevaDiligenciaForm(forms.Form):
    titulo = forms.CharField(max_length=70)    
    tipo = forms.ChoiceField(choices=TIPO)        
    vias= forms.TypedChoiceField(widget=forms.RadioSelect(), choices=CHOICES)

view.py

def add(request):        
    form = NuevaDiligenciaForm()
    errors =[]
    if request.method =='POST': 
        if not request.POST.get('titulo',''):
            errors.append('Titulo es requerido')
        if not request.POST.get('vias',''):
            errors.append('Vias es requerido')
        #if not errors:
    return render_to_response('account/add.html', { 'formulario':form ,'errors':errors},context_instance = RequestContext(request))   

template.html

{% if errors %}
    <ul>
        {% for error in errors %}
        <li>{{ error }}</li>
        {% endfor %}
    </ul>
{% endif %}

{% if message %}
        <p style="color: red;">{{ message }}</p>
{% endif %}
<form action='.' method='POST' class="nueva-diligencia"> 

{{ formulario.as_p }}

<input type="submit" value="Continuar">
</form>

Thanks again 🙂

  • 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. Editorial Team
    Editorial Team
    2026-05-12T10:06:11+00:00Added an answer on May 12, 2026 at 10:06 am

    You form code looks fine here but your view needs to change to this:

    def add(request):
    if request.method =='POST':
        form = NuevaDiligenciaForm(request.POST)
        if form.is_valid():
            clean_data = form.cleaned_data
            # Now do something with the cleaned data...
    else:
        form = NuevaDiligenciaForm()
    return render_to_response('account/add.html', { 'formulario': form }
    

    and your template should look like this:

    {% if message %}
    <p style="color: red;">{{ message }}</p>
    {% endif %}
    <form action='.' method='POST' class="nueva-diligencia"> 
        {{ formulario.as_p }}
        <input type="submit" value="Continuar">
    </form>
    

    Now what happens is that if there is bad data from the POST, form.is_valid() will fail and the view will return the validated form, which will include errors next to fields that have them. Django takes care of all the error handling for you here! Try it out and let me know if it works as you expect it to.

    This is a pretty good resource if you’d like to see how/why this simplified version actually works better: http://www.djangobook.com/en/2.0/chapter07/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning jQuery right now and am looking to validate form fields with
I have committed to learning C now, I'm good with Python/PHP/Bash but I've decided
I have mostly programmed in Python, but I am now learning the statistical programming
I came from PHP language(codeigniter), but now I learning ASP.Net MVC :) In PHP
I'm just learning MVC3 now and this is really confusing me. I have a
I'm learning scheme and until now have been using guile. I'm really just learning
I have been progressing through Learn Prolog Now! as self-study and am now learning
I'm now learning Tcl/Tk, but as I'm running Windows, I want to create a
I'm now learning a bit of MATLAB and I have two versions of it.
We have a new developer that is just now learning LinqToSql. While going over

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.