Skip to content

Instantly share code, notes, and snippets.

@vitorfs

vitorfs/views.py Secret

Created Oct 8, 2017
Embed
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 = 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
@sachinchavan9

This comment has been minimized.

Copy link

@sachinchavan9 sachinchavan9 commented Feb 1, 2018

@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

untitled

@Aseyed

This comment has been minimized.

Copy link

@Aseyed Aseyed commented Aug 7, 2018

@sachinchavan9
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