___forms py from django import forms from django contrib auth models i

 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
___forms.py
from django import forms
from django.contrib.auth.models import User
class RegistrForm(forms.Form):
username = forms.CharField(max_length=30)
password1 = forms.CharField(max_length=30)
password2 = forms.CharField(max_length=30)
email = forms.EmailField(max_length=40)
def save(self):
#username = self.cleaned_data['username']
#email = self.cleaned_data['email']
#password = self.cleaned_data['password1']
user = User.objects.create_user(username=username,
password=password,
email=email)
#user.is_active = True
user.save()
return user
____views.py
def reg(request):
if request.method == 'POST':
form = RegistrForm(request.POST)
if form.is_valid:
#username = form.cleaned_data['username']
#password1 = form.cleaned_data['password1']
#password2 = form.cleaned_data['password2']
#email = form.cleaned_data['email']
form.save()
HttpResponseRedirect('/thanks/')
else:
form = RegistrForm()
return render_to_response("sitereg/register.html", {'form' : form})