Best practices :3
This commit is contained in:
parent
da7baed79c
commit
9d82b20151
2 changed files with 7 additions and 3 deletions
|
@ -3,12 +3,16 @@ from pprint import pprint
|
||||||
from django.contrib.auth import logout
|
from django.contrib.auth import logout
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
from users.forms import UserMetaForm
|
from users.forms import UserMetaForm
|
||||||
from users.models import CustomUser
|
from users.models import CustomUser
|
||||||
|
|
||||||
|
|
||||||
def profile(request):
|
def profile(request):
|
||||||
|
if not request.user.is_authenticated:
|
||||||
|
return HttpResponseRedirect(reverse("events:index"))
|
||||||
|
|
||||||
# if this is a POST request we need to process the form data
|
# if this is a POST request we need to process the form data
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
# create a form instance and populate it with data from the request:
|
# create a form instance and populate it with data from the request:
|
||||||
|
@ -19,15 +23,15 @@ def profile(request):
|
||||||
form.save()
|
form.save()
|
||||||
# redirect to a new URL:
|
# redirect to a new URL:
|
||||||
|
|
||||||
return HttpResponseRedirect('/user/profile')
|
return HttpResponseRedirect(reverse("users:profile"))
|
||||||
|
|
||||||
# if a GET (or any other method) we'll create a blank form
|
# if a GET (or any other method) we'll create a blank form
|
||||||
else:
|
else:
|
||||||
form = UserMetaForm(instance=request.user)
|
form = UserMetaForm(instance=request.user)
|
||||||
|
|
||||||
return render(request, 'profile.html', {'form': form})
|
return render(request, 'users/profile.html', {'form': form})
|
||||||
|
|
||||||
def logout_view(request):
|
def logout_view(request):
|
||||||
logout(request)
|
logout(request)
|
||||||
|
|
||||||
return redirect('/user/profile')
|
return redirect(reverse("users:profile"))
|
||||||
|
|
Loading…
Reference in a new issue