Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

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

user-image
Question ajoutée par Hasan Zahran f
Date de publication: 2017/04/16
fadi attya
par 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
par Mhadi Ahmed Ahmed , Backend Developer , dot.energy

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

Ritto Thankankachan
par Ritto Thankankachan , Software Developer , Fleming

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

Syed Faizun Nabi
par 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