kers/users/views.py
2020-07-22 16:06:04 +02:00

33 lines
1,012 B
Python

from pprint import pprint
from django.contrib.auth import logout
from django.http import HttpResponseRedirect
from django.shortcuts import render, redirect
from users.forms import UserMetaForm
from users.models import CustomUser
def profile(request):
# if this is a POST request we need to process the form data
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = UserMetaForm(request.POST, instance=request.user)
# check whether it's valid:
if form.is_valid():
# process the data in form.cleaned_data as required
form.save()
# redirect to a new URL:
return HttpResponseRedirect('/user/profile')
# if a GET (or any other method) we'll create a blank form
else:
form = UserMetaForm(instance=request.user)
return render(request, 'profile.html', {'form': form})
def logout_view(request):
logout(request)
return redirect('/user/profile')