Skip to content

Instantly share code, notes, and snippets.


vitorfs/ Secret

Created Oct 8, 2017
What would you like to do?
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 =
auth_login(request, user)
return redirect('home')
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
Copy link

Aseyed commented Aug 7, 2018

Use this syntax:

def get_object(self, queryset=None):
    return self.request.user

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment