I have a very strange bug with fom errors. On my development site, my code works fine. But on my production site (apache + mod-wgsi + posgresql), the form errors I defined in is_valid() method of my ModelForm (in a generic CreateView) are not product by the template. Have you already seen such a thing ?
 
Here is my code :
 
 
views.py:
class UserCreate(CreateView):
    model = User
    template_name = 'base/userCreate.html'
    success_url = '/utilisateurs/nouveau/success/{id}'
    form_class = UtilisateurCreateForm
 
forms.py:
class UtilisateurCreateForm(forms.ModelForm):
    class Meta:
        model = User
        fields = ['first_name', 'last_name', 'email']
    def is_valid(self):
        valid =  super().is_valid()
        if email != '' and User.objects.filter(email = email).exists():
            self.add_error('email', 'Il existe déjà un utilisateur avec cet email.')
            valid = False
        return valid
 
userCreate.html:
{% extends "base/base.html" %}
{% block contenu %}
<h3>Nouvel utilisateur :</h3>
<form action="" method="post">{% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="Enregistrer" />
</form>
{% endblock %}
 
Thank's for your 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/trinity-68cd841e-22eb-421b-95ea-2b94ca00a28b-1471243983623%403capp-mailcom-bs11.
For more options, visit https://groups.google.com/d/optout.

Reply via email to