如何在django中显示错误消息

时间:2017-08-29 17:03:03

标签: python django python-2.7

因为我可以在完成表单字段时向用户发出错误消息,我正在使用基于类CreateView的视图...而我只找到success_message

class RegistroUsuario(CreateView):
model = User
template_name = "usuario/registrar.html"
form_class = RegistroForm
success_url = reverse_lazy('denuncias:index')
permission_denied_message = "You must login to contact the administrator"

我也尝试添加此功能,但在使用它时不再创建regitros

def form_invalid(self, form):
    response = super(RegistroUsuario, self).form_invalid(form)
    messages.error(
        self.request, 'Error de validacion: Email o contraseñas incorrectas, recuerde las contraseñas deben tener un minimo de 8 caracteres con letras y numeros')
    return response

1 个答案:

答案 0 :(得分:0)

将注册商表单重定向提交按钮填写到其他URL,显示注册成功或不成功 Like it is done in this for invalid_login.html