Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # forms.py
- class SignUpForm(UserCreationForm):
- first_name = forms.CharField(max_length=30, required=False, help_text='Optional.')
- last_name = forms.CharField(max_length=30, required=False, help_text='Optional.')
- email = forms.EmailField(max_length=254, help_text='Required. Inform a valid email address.')
- #estado = forms.CharField(required=True)
- class Meta:
- model = User
- fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2',)
- # view.py
- def signup(request):
- if request.method == 'POST':
- form = SignUpForm(request.POST)
- if form.is_valid():
- form.save()
- username = form.cleaned_data.get('username')
- raw_password = form.cleaned_data.get('password1')
- user = authenticate(username=username, password=raw_password)
- login(request, user)
- return redirect('home')
- else:
- form = SignUpForm()
- return render(request, 'Registration/signup.html', {'form': form})
- # signup.html
- {% block content %}
- <h2>Sign up</h2>
- <form method="post">
- {% csrf_token %}
- {% for field in form %}
- <p>
- {{ field.label_tag }}<br>
- {{ field }}
- {% if field.help_text %}
- <small style="color: grey">{{ field.help_text }}</small>
- {% endif %}
- {% for error in field.errors %}
- <p style="color: red">{{ error }}</p>
- {% endfor %}
- </p>
- {% endfor %}
- <button type="submit">Sign up</button>
- </form>
- {% endblock %}
Add Comment
Please, Sign In to add comment