-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathviews.py
51 lines (43 loc) · 1.79 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from django.shortcuts import render, redirect
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from .forms import SignUpForm, ProfileUpdate, UserUpdate
def Register(request):
if request.method == "POST":
form = SignUpForm(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
messages.success(request, f'Account created for {username}!')
password = form.cleaned_data.get('password1')
return redirect("Account")
else:
for msg in form.error_messages:
print(form.error_messages[msg])
return render(request = request,
template_name = "register.html",
context={"form":form})
form = SignUpForm
return render(request = request,
template_name = "register.html",
context={"form":form})
@login_required
def Account(request):
if request.method == 'POST':
user_form = UserUpdate(request.POST, instance=request.user)
profile_form = ProfileUpdate(request.POST,
request.FILES,
instance=request.user.profile)
if user_form.is_valid() and profile_form.is_valid():
user_form.save()
profile_form.save()
messages.success(request, f'Your account information has been updated successfully!')
return redirect('Account')
else:
user_form = UserUpdate(instance=request.user)
profile_form = ProfileUpdate(instance=request.user.profile)
context = {
'user_form': user_form,
'profile_form': profile_form
}
return render(request, 'account.html', context)