Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Showing Validation Error like a popup,instead of loading another page in Django?

user-image
Question added by Hasan Zahran f
Date Posted: 2017/04/16
fadi attya
by fadi attya , Full Stack Web Developer , Mabnna

I use Djando :

class SignUpFormss (forms.ModelForm): class Meta: model = SignUp fields=['email','fullname']def clean_email(self): email=self.cleaned_data.get('email')if not "gmail" in email: raise forms.ValidationError("please enter gmail.com")return email

Mhadi Ahmed Ahmed
by Mhadi Ahmed Ahmed , Backend Developer , dot.energy

use a client side validation like (jquery) or you can just use ajax request 

Ritto Thankankachan
by Ritto Thankankachan , Software Developer , Fleming

ajax is the best option. most of the web sites are using this. 

Syed Faizun Nabi
by Syed Faizun Nabi , Software Developer , Al Rumaithy

Use Ajax to poll the data and trigger the popup if the data is valid.

Using ajax with Django is as simple as any other platform, but only one thing to keep in mind is setting the XHR for csrf (in case of posting data).

$.ajax({

            type: "POST",

            data: "uid={{id}}",

            url: "your app url",

            beforeSend: function(xhr, settings){

                            xhr.setRequestHeader('X-CSRFToken','{{ csrf_token }}');

                          },

            success: function(data) {

              alert(data);

            }

        }); 

More Questions Like This