I am working width Django now. But I don't make sense about that.
I want to get id and password from the form and check if the password from form is correct to compare with the password of database.
Following are the my codes.
Please help me.
models.py
from django.db import models
class Doctor(models.Model):
doctor_id = models.CharField(max_length=16, primary_key=True)
clinic_id = models.ForeignKey(Clinic)
doctor_email = models.CharField(max_length=64)
doctor_password = models.CharField(max_length=32)
doctor_name = models.CharField(max_length=32)
create_date = models.DateTimeField(auto_now_add=True)
modify_date = models.DateTimeField(auto_now=True)
forms.py
from django import forms
from .models import Doctor
class LoginForm(forms.Form):
class Meta:
model = Doctor
fields = ('doctor_id', 'doctor_password',)
views.py
from django.shortcuts import get_object_or_404, render
from django.http import HttpResponse
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from .forms import LoginForm
from .models import Doctor
#ensure_csrf_cookie
def user_login(request):
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
_id = form.cleaned_data['doctor_id']
_password = form.cleaned_data['doctor_password']
b = Doctor.objects.all().filter(doctor_id=_id)
if _password is doctor_password:
login(request, user)
return HttpResponse('Authenticated successfully')
else:
return HttpResponse('Disabled account')
else:
return HttpResponse('Invalid login')
else:
form = LoginForm()
return render(request, 'apiv1/login.html', {'form': form})
login.html
{% extends "base.html" %}
{% load staticfiles%}
{% block title%}Title{% endblock %}
{% block remoshincss %}/static/css/style.css{% endblock %}
{% block content %}
<div class="container">
<div align="center" class="imgtop"><img id="profile-img" class="profile-img-card" src="/static/img/remoshinlogo.png" /></div>
<div class="card card-container">
<p id="profile-name" class="profile-name-card"></p>
<form class="form-signin" action="{% url 'login' %}" method="post">{% csrf_token %}
<input type="user" id="userid" name="userid" class="form-control inputUser" placeholder="USER-ID" autofocus>
<input type="password" id="password" name="password" class="form-control inputPassword" placeholder="PASSWORD">
<input type="hidden" name="next" value="{{ next }}" />
<br>
<div align="center"><button style="width: 200px;" class="btn btn-lg btn-primary btn-block btn-signin" type="submit"><font color="#708090">Login</font></button></div>
</form>
</div>
</div>
{% endblock %}
Import check_password
from django.contrib.auth.hashers import check_password
check password
pass_ = check_password(_password, b.doctor_password)
if pass_ is False:
return HttpResponse('Invalid login')
Code:
#ensure_csrf_cookie
def user_login(request):
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
_id = form.cleaned_data['doctor_id']
_password = form.cleaned_data['doctor_password']
docter = Doctor.objects.filter(doctor_id=_id).last()
if docter is None:
return HttpResponse('Invalid login')
pass_ = check_password(_password, docter.doctor_password)
if pass_ is False:
return HttpResponse('Invalid login')
return HttpResponse('Authenticated successfully')
else:
return HttpResponse('Invalid login')
else:
form = LoginForm()
return render(request, 'apiv1/login.html', {'form': form})
Related
I am creating a simple django models of doctors and department. there is not link between them and when I try to update the department then it is show me this error IntegrityError at /update_dept/1/ NOT NULL constraint failed: main_department.dept_name this error is new for me. I check other similar question also but didn't get much. so pls help me.
here is my view.py file
from django.shortcuts import render
from .forms import Doctorslist,Departmentform
from .models import Department, Doctor
from django.shortcuts import redirect
from django.views.generic import (CreateView, DetailView, UpdateView, ListView, TemplateView, DeleteView)
from django.contrib.messages import constants as messages
import os
# Create your views here.
def add_show(request):
form = Doctorslist()
if request.method == "POST":
form = Doctorslist(request.POST, request.FILES)
form.save()
return redirect('/')
else:
form = Doctorslist()
stud = Doctor.objects.all
context = {'form':form,
'stu':stud
}
return render(request, 'main/index.html', context)
def update_data(request, id):
prod = Doctor.objects.get(id=id)
if request.method == "POST":
prod.doc_image = request.FILES['doc_image']
prod.kycdocument = request.FILES['kycdocument']
prod.name = request.POST.get('name')
prod.phone_number = request.POST.get('phone_number')
prod.email = request.POST.get('email')
prod.city = request.POST.get('city')
prod.speciality = request.POST.get('email')
prod.save()
messages.success(request, "Product Updated Successfully")
return redirect('/')
context = {'prod':prod}
return render(request, 'main/update_doc.html', context)
def delete_data(request,id):
if request.method =='POST':
pi = Doctor.objects.get(pk = id)
pi.delete()
return redirect('/')
def add_show_dept(request):
form = Departmentform()
if request.method == "POST":
form = Departmentform(request.POST)
form.save()
return redirect('/')
else:
form = Departmentform()
dept = Department.objects.all
context = {'form':form,
'stu':dept
}
return render(request, 'main/pages-profile.html', context)
def update_dept_data(request, id):
prod = Department.objects.get(id=id)
if request.method == "POST":
prod.dept_name = request.POST.get('dept_name')
prod.dept_Email = request.POST.get('dept_Email')
prod.save()
messages.success(request, "Product Updated Successfully")
return redirect('/')
context = {'prod':prod}
return render(request, 'main/update_dept.html', context)
here is model.py
from django.db import models
from phonenumber_field.modelfields import PhoneNumberField
import os
# Create your models here.
import datetime
def get_file_path(request, filename):
filename_original = filename
nowTime = datetime.datetime.now().strftime('%Y%m%d%H:%M:%S')
filename = "%s%s" % (nowTime, filename_original)
return os.path.join('uploads/', filename)
class Doctor(models.Model):
name = models.CharField(max_length=20)
phone_number = PhoneNumberField(null=False, blank=False, unique=True)
email = models.EmailField(max_length = 100)
city = models.CharField(max_length=100)
speciality = models.CharField(max_length=50)
doc_image = models.ImageField(upload_to = get_file_path)
kycdocument = models.ImageField(upload_to = get_file_path, null = True, blank = True)
class Department(models.Model):
dept_name = models.CharField(max_length=20)
dept_Email = models.EmailField(max_length=100)
dept_password = models.CharField(max_length=200)
here is forms.py file
from django import forms
from phonenumber_field.modelfields import PhoneNumberField
from .models import Doctor,Department
class Doctorslist(forms.ModelForm):
class Meta:
model = Doctor
fields = ('name','phone_number','email', 'city', 'speciality', 'doc_image', 'kycdocument')
# widgets = {
# 'name': forms.TextInput(attrs = {'class': 'form-control'}),
# 'email': forms.EmailInput(attrs={'class': 'form-control'}),
# 'city': forms.CharField(attrs={'class': 'form-control'}),
# 'speciality': forms.CharField(attrs={'class': 'form-control'}),
# }
class Departmentform(forms.ModelForm):
class Meta:
model = Department
fields = ('dept_name','dept_Email','dept_password')
widgets = {'dept_password': forms.PasswordInput()}
here is update_dept.html file
{% extends 'base.html' %}
{% block content %}
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">
<h2 class="fw-bold">Edit Product</h2>
</div>
<div class="card-body">
<form action="" method="POST" enctype="multipart/form-data">
{% csrf_token %}
<div class="mb-3">
<label for="" class="form-label">Name</label>
<input type="text" Required name="name" value="{{ prod.dept_name }}" class="form-control">
</div>
<div class="mb-3">
<label for="" class="form-label">Email</label>
<input type="text" Required name="price" value="{{ prod.dept_Email }}" class="form-control">
</div>
<button type="submit" class="btn btn-warning">Update</button>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
Your HTML form uses the wrong names, and therefore request.POST does not contain any entries like dept_name and dept_Email. You should specify name="dept_name" instead of name="name" and name="dept_Email" instead of name="price":
<div class="mb-3">
<label for="" class="form-label">Name</label>
<input type="text" Required name="dept_name" value="{{ prod.dept_name }}" class="form-control">
</div>
<div class="mb-3">
<label for="" class="form-label">Email</label>
<input type="text" Required name="dept_Email" value="{{ prod.dept_Email }}" class="form-control">
</div>
That being said, I would strongly advise that you use a ModelForm, you can make a second ModelForm for the department where you leave out the dept_password.
You can see the Rendering fields manually section of the documentation that shows how you can render you Django form with custom HTML.
I'm trying to make a post request, I have created the models as well, but for some reason, it is giving me the following error
I understand that this mean there is some mistyped, but when I check the html and views.py, I don't see any mistake, everything should be in order
financiamiento.html
{% extends "Portafolio/layout.html" %}
{%block content %}
<br>
<div class="text-center">
<form action="{% url 'financiamiento'%}" method="POST" style="max-width:800px;margin:auto;">
{% csrf_token %}
<h1 class="mt-5">Perspectiva Financiera</h1>
<h1 class="h3 mb-10 mt-2">Financiamiento</h1>
<label class="sr-only"></label>
<input name= "MontoProyecto" type="text" id="MontoProyecto" placeholder="Monto Aporte Proyecto"class="form-control">
<label class="sr-only"></label>
<input name= "MontoPropio" type="text" id="MontoPropio" placeholder="Monto Aporte Propio"class="form-control">
<label class="sr-only"></label>
<input name="MontoBanca" type="text" id="MontoBanca" placeholder="Monto Aporte Banca"class="form-control">
<label class="sr-only"></label>
<input name="MontoPublico" type="text" id="MontoPublico" placeholder="Monto Aporte Publico"class="form-control">
<div class="d-grid gap-2 mt-3">
<input type="submit" class="btn btn-lg btn-primary">
</div>
</form>
</div>
{% endblock %}
views.py
from django.http.response import HttpResponse
from django.shortcuts import redirect, render
from django.http import HttpResponse
from .models import Proyecto, Financiamiento
# Create your views here.
def index(request):
return render (request, "Portafolio/index.html",{
"financiamiento":Financiamiento.objects.all()
})
def registroproyecto(request):
if request.method == 'POST':
NombreProyecto = request.POST.get('NombreProyecto')
ResponsableProyecto = request.POST.get('ResponsableProyecto')
EvaluadorProyecto = request.POST.get('EvaluadorProyecto')
DescripcionProyecto = request.POST.get('DescripcionProyecto')
Proyecto.objects.create(NombreProyecto=NombreProyecto, ResponsableProyecto=ResponsableProyecto, EvaluadorProyecto=EvaluadorProyecto, DescripcionProyecto=DescripcionProyecto)
return redirect("/Portafolio")
return render (request, "Portafolio/RegistroProyecto.html")
def financiamiento(request):
if request.method == 'POST':
MontoProyecto = request.POST.get('MontoProyecto')
MontoPropio = request.POST.get('MontoPropio')
MontoBanca = request.POST.get('MontoBanca')
MontoPublico = request.POST.get('MontoPublico')
Financiamiento.objects.create(MontoProyecto=MontoProyecto, MontoPropio=MontoPropio, MontoBanca=MontoBanca, MontoPublico=MontoPublico)
return redirect("/Portafolio")
return render (request, "Portafolio/Financiamiento.html")
Also, something draw my attention, when I made the Financiamiento table, when I checked with the django admin, it didn't me allow to put input data, that is normal?
models.py
from django.db import models
# Create your models here.
class Proyecto(models.Model):
NombreProyecto = models.CharField(max_length=64)
ResponsableProyecto = models.CharField(max_length=64)
EvaluadorProyecto = models.CharField(max_length=64)
DescripcionProyecto = models.CharField(max_length=500)
class Financiamiento(models.Model):
MontoProyecto = models.IntegerField
MontoPropio = models.IntegerField
MontoBanca = models.IntegerField
MontoPublico = models.IntegerField
admin.py
from django.contrib import admin
from .models import Proyecto, Financiamiento
# Register your models here.
admin.site.register(Proyecto)
admin.site.register(Financiamiento)
In models.py all fields you have are IntegerFields. So, in your views.py you should convert the elements from string to integers first:
def financiamiento(request):
if request.method == 'POST':
MontoProyecto = int(request.POST.get('MontoProyecto'))
MontoPropio = int(request.POST.get('MontoPropio'))
MontoBanca = int(request.POST.get('MontoBanca'))
MontoPublico = int(request.POST.get('MontoPublico'))
Financiamiento.objects.create(MontoProyecto=MontoProyecto, MontoPropio=MontoPropio, MontoBanca=MontoBanca, MontoPublico=MontoPublico)
return redirect("/Portafolio")
return render (request, "Portafolio/Financiamiento.html")
when I try to add details using this form it is not updating to my database.
please help me to solve this issue.
There is no error but the database is not updated.
club.html
{% extends "base.html" %}
{% block content %}
{%ifequal request.user.Isclubmember True%}
<div class='container'>
</div>
{%else%}
<div class="container">
<form action="." method="POST">
{%csrf_token%}
Profile Pic:
<input name="image" accept=".png,.jpg,.jpeg" type="file" value=selectimage>
Phonenumber:
<input name="userphonenumber" type="number" placeholder="+91 9876543210" >
<input type="submit" value="submit" class="btn btn-success">
</form>
</div>
{%endifequal%}
{% endblock content %}
views.py
from django.conf import settings
from django.contrib import messages
from django.shortcuts import redirect
from django.contrib.auth.models import User
from .models import UserProfile, Clubmember
from django.contrib.auth.models import User
from django.contrib.auth import login
from django.http import HttpResponseRedirect
def club(request):
if request.method == 'POST':
if request.user.is_authenticated:
Clubmember.user = request.user
Clubmember.phone_number = request.POST.get('userphonenumber')
Clubmember.userphoto = request.FILES.get('image')
request.user.Isclubmember = True
request.user.save()
Clubmember.save()
return redirect(request,'core:home')
else:
return redirect(request,'login_url')
else:
return render(request,'core:club')
models.py
class Clubmember(models.Model):
user = models.ForeignKey(UserProfile,default=1, on_delete=models.CASCADE)
userphoto = models.ImageField(upload_to="userphotos/%Y/%m",default=False)
phone_number = models.IntegerField(default=False)
usermoney = models.FloatField(default=0.0)
Change the view like this, it should work.
def club(request):
if request.method == 'POST':
if request.user.is_authenticated:
club_member = Clubmember()
club_member.user = request.user
club_member.phone_number = request.POST.get('userphonenumber')
club_member.userphoto = request.FILES.get('image')
request.user.Isclubmember = True
request.user.save()
club_member.save()
return redirect(request,'core:home')
else:
return redirect(request,'login_url')
else:
return render(request,'core:club')
and a better approach is
def club(request):
if request.method == 'POST':
if request.user.is_authenticated:
club_member = Clubmember(
user=request.user,
phone_number=request.POST.get('userphonenumber'),
userphoto=request.FILES.get('image')
)
club_member.save()
request.user.Isclubmember = True
request.user.save()
return redirect(request,'core:home')
else:
return redirect(request,'login_url')
else:
return render(request,'core:club')
So when the form is invalid and I click submit, it just redirects to /home because of return redirect('/'). So what do I have to return here to prevent form submission and raise an error message? Here's my code:
views.py
class BoxesView(ListView, FormMixin):
template_name = 'polls.html' # extends base.html
form_class = UserRegistrationForm
def get_context_data(self, **kwargs):
context = super(BoxesView, self).get_context_data()
question_list = Question.objects.all().order_by('-date')
choice = Choice.objects.all()
context['question_list'] = question_list
context['choice'] = choice
q_list = []
returned_list = []
for i in question_list:
q_list.append(i)
for a, b in CATEGORY_CHOICES:
name = resolve(self.request.path_info).url_name
if b == name:
category = a
search = self.request.GET.get('search')
posts = Post.objects.all().filter(category=category).order_by('-date')
if search:
posts = posts.filter(
Q(title__icontains=search) |
Q(content__icontains=search)
)
else:
posts = Post.objects.all().filter(category=category).order_by('-date')
context['posts'] = posts
total = 0
for post in posts:
returned_list.append(post)
total += 1
if total == 4:
total = 0
for i in q_list:
returned_list.append(i)
q_list.remove(i)
break
paginator = Paginator(returned_list, 14)
page = self.request.GET.get('page')
try:
lst = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
lst = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
lst = paginator.page(paginator.num_pages)
context['lst'] = lst
return context
def get_queryset(self):
pass
def register(request):
form = UserRegistrationForm(request.POST)
if form.is_valid():
username = form.cleaned_data['username']
password = form.cleaned_data['password']
email = form.cleaned_data['email']
user = User.objects.create_user(username=username, password=password, email=email)
user.save()
return redirect('/')
else:
print(form.errors)
form = UserRegistrationForm()
return redirect('/')
And in my forms.py it raises an exception error to the terminal but the form still submits.
forms.py
class UserRegistrationForm(forms.ModelForm):
email = forms.EmailField()
username = forms.CharField(max_length=25)
password = forms.CharField(widget=forms.PasswordInput)
confirm_password = forms.CharField(widget=forms.PasswordInput)
class Meta:
model = User
fields = [
'username',
'email',
'password',
]
def clean(self):
email = self.cleaned_data.get('email')
current_emails = User.objects.filter(email=email)
if current_emails.exists():
raise forms.ValidationError("That email is taken")
base.html
<form method="post" enctype="multipart/form-data" action="{% url 'register' %}">{% csrf_token %}
<div class="registerBox">
<p><label for="id_username"></label> <input id="id_username" type="text" name="username" maxlength="30" placeholder="username"/></p>
<p><label for="id_email"></label> <input type="email" name="email" id="id_email" placeholder="email"/></p>
<p><label for="id_password"></label> <input type="password" name="password" id="id_password" placeholder="password"/></p>
<p><label for="id_confirm_password"></label> <input type="password" name="confirm_password" id="id_confirm_password" placeholder="confirm password"/></p>
<input type="submit" value="register" />
</div>
</form>
Any idea?
You shouldn't be trying to prevent submission when the form is invalid. What you should be doing is accepting the submission, checking the errors, then returning the errors and the filled-in form to the template.
But you are doing three things that prevent that: you are always re-instantiating the form when it is invalid, you always redirect, and you don't show errors or previous values in the template.
So you should do this:
def register(request):
form = UserRegistrationForm(request.POST)
if form.is_valid():
username = form.cleaned_data['username']
password = form.cleaned_data['password']
email = form.cleaned_data['email']
user = User.objects.create_user(username=username, password=password, email=email)
user.save()
return redirect('/')
return render('mytemplate.html', {"form": form})
and in the template:
<div class="registerBox">
{{ form.non_field_errors }}
<p>{{ form.username.label_tag }} {{ form.username }} {{ form.username.errors }}</p>
<p>{{ form.email.label_tag }} {{ form.email }} {{ form.email.errors }}</p>
<p><label for="id_password"></label> <input type="password" name="password" id="id_password" placeholder="password"/></p>
<p><label for="id_confirm_password"></label> <input type="password" name="confirm_password" id="id_confirm_password" placeholder="confirm password"/></p>
<input type="submit" value="register" />
</div>
have you tried
if form.is_valid():
...
else:
return form_invalid(form)
You should use ajax validation if you do not want to submit invalid form.
Trying to build a fashion technology application and as I am setting the forms, views, models and templates everything seems fine, and I get the CSRF verification failed error. Any clue as to what I am doing wrong?
models.py:
from django.db import models
from django.contrib.auth.models import User
class ProfileUser(models.Model):
user = models.OneToOneField(User,unique=True)
birthday = models.DateField(null=True,blank=True)
city = models.CharField(max_length=50,blank=True)
state = models.CharField(max_length=50,blank=True)
user_title = models.CharField(max_length=254, verbose_name="Influencer Level", blank=True)
user_points = models.IntegerField(null=False, verbose_name="Influence Credit", blank=True)
picture = models.ImageField(upload_to='images', blank=True)
#admin level and additional infomation
is_staff = models.BooleanField(default=False)
#Override the _unicode_() method to return out something meaningful
def _unicode_(self):
return self.user.username
forms.py:
#coding=utf-8
from django import forms
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
from django.forms import extras
from models import ProfileUser
###### Login for users ###########
# class LoginForm(forms.Form):
# username=forms.CharField(label=_(u"username"),max_length=30,widget=forms.TextInput(attrs={'size': 20,}))
# password=forms.CharField(label=_(u"password"),max_length=30,widget=forms.PasswordInput(attrs={'size': 20,}))
# class Meta:
# """docstring for Meta"""
# model = User
###### Registration for users ###########
class RegisterForm(forms.ModelForm):
email=forms.EmailField(max_length=30, widget=forms.TextInput(attrs={'placeholder': 'Email', 'required':True}))
username=forms.CharField(max_length=30, widget=forms.TextInput(attrs={'placeholder': 'Username','required':True}))
password=forms.CharField(max_length=30, widget=forms.PasswordInput(attrs={'placeholder': 'Password','required':True}))
password2=forms.CharField(max_length=30, widget=forms.PasswordInput(attrs={'placeholder': 'Re-Enter Password','required':True}))
class Meta:
"""The model that is extened from django models and the fields below are specified to prevent abstraction"""
model = User
fields = ('email', 'username', 'password', 'password2')
def clean(self):
cleaned_data = super(RegisterForm, self).clean()
email = cleaned_data.get('email')
username = cleaned_data.get('username')
password = cleaned_data.get('password')
password2 = cleaned_data.get('password2')
#check if username exist
user = User.objects.filter(username=username)
if user:
raise forms.ValidationError("this username is already exsist")
#check for password and re-enter password
if password != password2:
raise forms.ValidationError("Password does not match")
#check for email is system
emails = User.objects.filter(email=email)
if email:
raise forms.ValidationError("this email is already registered")
return cleaned_data
views.py:
#coding=utf-8
from django.shortcuts import render
from django.core.urlresolvers import reverse
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.contrib import messages
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login as auth_login ,logout as auth_logout
from django.utils.translation import ugettext_lazy as _
from forms import RegisterForm
from models import ProfileUser
###### Login for users ###########
# def login(request):
# template_var={}
# form = LoginForm()
# if request.method == 'POST':
# form = LoginForm(request.POST.copy())
# if form.is_valid():
# _login(request,form.cleaned_data["username"],form.cleaned_data["password"])
# return HttpResponseRedirect(reverse("login"))
# template_var["form"]=form
# return render_to_response("registration/login.html",template_var,context_instance=RequestContext(request))
# def _login(request,username,password):
# ret = False
# user = authenticate(username=username,password=password)
# if user:
# if user.is_active:
# auth_login(request,user)
# ret=True
# else:
# messages.add_message(request, messages.INFO, _(u'user is not active'))
# else:
# messages.add_message(request, messages.INFO, _(u'Incorrect username or password'))
# return ret
###### Registration for users ###########
def register(request):
if request.user.is_authenticated():
return HttpResponseRedirect(reverse('success'))
form = RegisterForm() # this will is used in the GET request
if request.method=="POST":
form=RegisterForm(request.POST)
if form.is_valid():
user = User.objects.create_user(
username=form.cleaned_data["username"],
email=form.cleaned_data["email"],
password=form.cleaned_data["password"]
)
user.is_active = True
user.save()
return redirect('base')
else:
return render_to_response("registration/signup.html",context_instance=RequestContext(request))
person = authenticate(
username=form.cleaned_data['username'],
password=form.cleaned_data['password']
)
login(request, person)
return HttpResponseRedirect(reverse("success"))
return render_to_response("registration/signup.html",context_instance=RequestContext(request))
Template:
{% extends 'home/base.html' %}
{% block title %}Signup with Indieitude{% endblock title %}
{% block search %}
{% endblock search %}
{% block space %}
<div class="space-registration"></div>
{% endblock space %}
{% block signup %}
<div id="content">
<div class="block">
<div class="box-login">
<div class="head">
<h2 class="heading-title">Start Discovering</h2>
<p align="center"><em>Log in with your Facebook</em>
</p>
</div>
<div class="socialconnect"> Log in with Facebook
</div>
<p align="center"><em>Or signup with your email & name</em>
</p>
<div class="box-form">
<form action="" method="post">{% csrf_token %}
<p>
{{form.email}}
</p>
<p>
{{form.username}}
</p>
<p>
{{form.password}}
</p>
<p>
<!-- <input type="password" id="" name="" required="required" class="text-input" placeHolder="Re-Enter Password" /> -->
</p>
<p class="agree">By signing up, I agree to Indieitude's Terms of Service & Privacy Policy
</p>
<p>
<input type="submit" name="submit" value="register" class="button large bold">
</p>
</form>
</div>
<div class="footer">
<h2 class="heading-title" align="center">Already have an account? Login</h2>
</div>
</div>
</div>
</div>
{% endblock signup %}
In views.py,
from django.core.context_processors import csrf
def register(request):
if request.user.is_authenticated():
return HttpResponseRedirect(reverse('success'))
if request.POST:
form=RegisterForm(request.POST)
if form.is_valid():
user = User.objects.create_user(
username=form.cleaned_data["username"],
email=form.cleaned_data["email"],
password=form.cleaned_data["password"]
)
user.is_active = True
user.save()
return redirect('base')
else:
form = RegisterForm()
args = {'form' : form}
args.update(csrf(request))
return render_to_response("registration/signup.html", args)