add_error() takes exactly 2 arguments (3 given)
/home/victor/Documents/Codigos/website/users/views.py in post
if form.is_valid(): ...
▶ Local vars
/home/victor/Documents/Codigos/website/users/forms.py in is_valid
if not super(RegisterUserForm, self).is_valid(): ...
▶ Local vars
Não to sabendo onde arrumar o erro e oq ele significa
users/views.py
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.views.generic.base import View
from django.contrib.auth.models import User
from .forms import *
from curriculum.models import Profile
class RegisterUserView(View):
template = 'users/register.html'
def get(self, request):
return render(request, self.template)
def post(self, request):
form = RegisterUserForm(request.POST)
if form.is_valid():
user = User.objects.create_user(form.data['username'], form.data['email'], form.data['password'])
profile = Profile(first_name=form.data['name'],
user = user)
profile.save()
return HttpResponseRedirect(reverse('curriculum:home', args=(profile.id,)))
return render(request, self.template, {'form': form})
users/forms.py
from django import forms
from django.contrib.auth.models import User
class RegisterUserForm(forms.Form):
name = forms.CharField(required=True)
username = forms.CharField(required=True)
email = forms.EmailField(required=True)
password = forms.CharField(required=True)
def is_valid(self):
valid = True
if not super(RegisterUserForm, self).is_valid():
self.add_error('Please check the information provided')
valid = False
user_exists = User.objects.filter(username=self.data['username']).exists()
if user_exists:
self.add_error('User already exists')
valid = False
return valid
def add_error(self, message):
errors = self._errors.setdefault(forms.forms.NON_FIELD_ERRORS, forms.utils.ErrorList())
errors.append(message)
users/register.html
{% extends 'users/base.html' %}
{% block body %}
<form class="form-signin" action="{% url 'users:register' %}" method="post">
{% csrf_token %}
<h2 class="form-signin-heading">Cadastro</h2>
<input id="id_name" name="name" type="text" class="form-control" placeholder="name" value="{{form.name.value}}" required autofocus/>
<input id="id_username" name="username" type="text" class="form-control" placeholder="Username" value="{{form.username.value}}" required />
<input id="id_email" name="email" type="text" class="form-control" placeholder="Email" value="{{form.email.value}}" required />
<input id="id_password" name="password" type="password" class="form-control" placeholder="Password" required />
<hr />
{% if form.erros %}
<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
{{form.non_field_errors}}
</div>
{% endif %}
<button class="btn btn-lg btn-primary btn-block" type="submit">Register</button>
</form>
{% endblock %}