I am trying to display form.erros. I am using bootstrap modal and using 
ajax form submit to send data async. Everything works fine... I can see the 
error messages returned in code. But it automatically goes to default error 
pages of django when form.is_valid returns false. When I print form in 
debug mode I see the specific error. I am using Werkzeug  for debugging. 

Here is my view.py code

def register_user(request):
    #args=UserCreationForm()
   
    args={}
    args.update(csrf(request))
    
    if request.method=='POST':   
        form = UserCreationForm(request.POST)
        print 'step 2'
        args['form']=form
        if form.is_valid:
            form.save()
            print 'step 3'
            return HttpResponseRedirect('/accounts/register_success/')
        else:

            return 
render_to_response('register.html',args,context_instance=RequestContext(request))
           
            #assert false
            #return 
render_to_response('register.html',args,context_instance=RequestContext(request))
    else:
        args['form'] = UserCreationForm()
    return 
render_to_response('register.html',args,context_instance=RequestContext(request))
    

======================================================================================
template code
<form id="signup" class="form-horizontal"  action='/accounts/register/' 
method='post' role='form'>{%csrf_token%}
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" 
aria-hidden="true">&times;</button>
    <h4 class="modal-title">Register</h4>
</div>           
    <div class="modal-body" id="modalbody">
        {%if form.errors %}
        <p>{{errors}}</p>
        {%endif%}
        <div class="form-group">
            <p>{{form.username.errors.as_text}}</p>
            <label for="username" class="col-sm-3 control-label">Choose 
Username</label>
            <div class="col-sm-5">
                <input type="text" name="username" class="form-control" 
value="" id="username" placeholder="Choose Username">
            </div>
        </div>
        
        <div class="form-group">
            <p>{{form.password1.errors.as_text }}</p>
            <label for="password1" class="col-sm-3 control-label">Choose 
Password</label>
            <div class="col-sm-5">
  
                <input type="password" name="password1" 
class="form-control" value="" id="password1" placeholder="Choose Password">

            </div>
        </div>
        
        <div class="form-group">
            <p>{{form.password2.errors.as_text }}</p>
            <label for="password2" class="col-sm-3 control-label">Re-Enter 
Password</label>
            <div class="col-sm-5">
                <input type="password" name="password2" 
class="form-control" value="" id="password2" placeholder="Re-Enter 
Password">
            </div>
        </div>
     
    </div>
<div class="modal-footer">
    <div class="form-group">
        <div class="col-lg-4">
            <div class="pull-left">
                <input type ="submit"  value="Register" class="btn 
btn-success btn-lg">
            </div>
        </div>
    </div>
</div>
</form> 

<script>
 
       $(document).ready(function() { 
           // bind 'myForm' and provide a simple callback function
   
        var form_options = {                     
                            target: '#modalcontent'
    
                          ,success: function() {
                               
                                                }                    
                    
                            
                            ,type: 'post'
                            //,clearForm: true
                            } 
        $('#signup').ajaxForm(form_options);
       
        });
  
 
       
</script> 

Please help

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/816d967e-60a6-46a2-b5c0-6f0073a62f7c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to