-
-
Save vitorfs/ea62417b7a450050f2feeeb69b775996 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.auth import login as auth_login | |
from django.contrib.auth.decorators import login_required | |
from django.contrib.auth.models import User | |
from django.shortcuts import redirect, render | |
from django.urls import reverse_lazy | |
from django.utils.decorators import method_decorator | |
from django.views.generic import UpdateView | |
from .forms import SignUpForm | |
def signup(request): | |
if request.method == 'POST': | |
form = SignUpForm(request.POST) | |
if form.is_valid(): | |
user = form.save() | |
auth_login(request, user) | |
return redirect('home') | |
else: | |
form = SignUpForm() | |
return render(request, 'signup.html', {'form': form}) | |
@method_decorator(login_required, name='dispatch') | |
class UserUpdateView(UpdateView): | |
model = User | |
fields = ('first_name', 'last_name', 'email', ) | |
template_name = 'my_account.html' | |
success_url = reverse_lazy('my_account') | |
def get_object(self): | |
return self.request.user |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@method_decorator(login_required, name='dispatch')
class UserUpdateView(UpdateView):
model = User
fields = ('first_name', 'last_name', 'email',)
template_name = 'my_account.html'
success_url = reverse_lazy('my_account')