i'm trying to signup with an otp for verification by sending email to the user mail, but getting this error, it's might be problem with signup.html, from where trying to get specific user otp to validate the data, if is there any better solution do this with django would be appreciate,
models.py
class User(AbstractUser):
username = None
email = models.EmailField(_('email address'), unique=True)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
is_buyer = models.BooleanField(default=False)
is_vendor = models.BooleanField(default=False)
objects = CustomUserManager()
def __str__(self):
return self.email
class UserOTP(models.Model):
user = models.ForeignKey(User, on_delete = models.CASCADE)
time_st = models.DateTimeField(auto_now = True)
otp = models.SmallIntegerField()
class Vendor(models.Model):
user = models.OneToOneField(User, related_name='vendor', on_delete=models.CASCADE)
business_name = models.CharField(max_length=50)
def __str__(self):
return self.user.email
forms.py
class VendorSignUpForm(UserCreationForm):
business_name = forms.CharField(required=True)
email = forms.EmailField(max_length=254, help_text='Required. Inform a valid email address.')
class Meta:
model = User
fields = ('business_name', 'email', 'password1', 'password2', )
#transaction.atomic
def save(self):
user = super().save(commit=False)
user.is_vendor = True
user.save()
customer = Vendor.objects.create(user=user)
customer.business_name=self.cleaned_data.get('business_name')
customer.save()
return user
views.py
def signup(request):
if request.method == 'POST':
get_otp = request.POST.get('otp')
print(get_otp)
if get_otp:
get_user = request.POST.get('user')
user = User.objects.get(email=get_user)
if int(get_otp) == UserOTP.objects.filter(user = user).last().otp:
user.is_active = True
user.save()
messages.success(request, f'Account is Created For {user.email}')
return redirect('login')
else:
messages.warning(request, f'You Entered a Wrong OTP')
return render(request, 'registration/signup.html', {'otp': True, 'user': user})
form = VendorSignUpForm(request.POST)
if form.is_valid():
form.save()
email = form.cleaned_data.get('email')
user = User.objects.get(email=email)
print(user)
user.email = email
user.is_active = False
user.save()
usr_otp = random.randint(100000, 999999)
UserOTP.objects.create(user=user, otp = usr_otp)
mess = f"Hello {user.email},\nYour OTP is {usr_otp}\nThanks!"
send_mail( 'Welcome to Costume Base - Verify Your Email',
mess , settings.DEFAULT_FROM_EMAIL, [user.email],
fail_silently = False)
return render(request, 'registration/signup.html', {'otp': True, user: user})
else:
form = VendorSignUpForm()
return render(request, 'registration/signup.html', {'form': form})
signup.html
{% block content %}
<div>
<h2>Signup</h2>
</div>
<div>
{% if otp %}
<form method="POST">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom display">
<h3 class="float-left">Verify Your Email</h3>
</legend>
** is this input value showing the error? **
<input type="hidden" value="{{user.email}}" name = 'user' >
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">OTP</span>
</div>
<input type="text" class="form-control" placeholder="Enter Your OTP" aria-label="OTP"
aria-describedby="basic-addon1" name = 'otp'>
</div>
</fieldset>
<div class="form-grounp">
<button class="btn mainbtn" type="submit">Verify</button>
<small class="float-right text-muted"><i><a href="#" class="text-dark"
onclick="ReSendOTP('{{user.email}}', 'resendOTPmess')"><i id="resendOTPmess">Resend</i> OTP</a></small>
</div>
</form>
{% else %}
<form method="POST">
{% csrf_token %}
{{form.as_p}}
<button type="submit">Register</button>
</form>
</div>
{% endif %}
{% endblock content %}
From the Django documentation:
This exception is raised by the ORM when an expected object is not found. For example, QuerySet.get() will raise it when no object is found for the given lookups.
That's probably due to one of your Model.get() methods, e.g:
user = User.objects.get(email=get_user)
Try to handle it with a try/catch or use a .filter() method instead of .get()
Related
I have django app with authentication in it. I have forms.py file like this:
<form class="login_form" method="post" novalidate>
{% csrf_token %}
<div class="col-md-3 col-md-auto text-center">
<b>First Name:<b>
{{ form.first_name }}
{% if 'first_name' in error %}
<div style='color:red'>{{error.first_name.0.message}}</div>
{% endif %}
</div>
<div class="col-md-3 col-md-auto text-center">
<b>Last Name:<b>
{{ form.last_name }}
{% if 'last_name' in error %}
<div style='color:red'>{{error.last_name.0.message}}</div>
{% endif %}
</div>
<div class="col-md-3 col-md-auto text-center">
<b>username:<b>
{{ form.username }}
{% if 'username' in error %}
<div style='color:red'>{{error.username.0.message}}</div>
{% endif %}
</div>
<div class="col-md-3 col-md-auto text-center">
<b>Email:<b>
{{ form.email }}
{% if 'email' in error %}
<div style='color:red'>{{error.email.0.message}}</div>
{% endif %}
</div>
<div class="col-md-3 col-md-auto text-center">
<b>Password<b>
{{ form.password }}
{% if 'password' in error %}
<div style='color:red'>{{error.password.0.message}}</div>
{% endif %}
</div>
<div class="col-md-3 col-md-auto text-center">
<b>Confirm password:<b>
{{ form.confirm_password }}
{% if 'confirm_password' in error %}
<div style='color:red'>{{error.confirm_password.0.message}}</div>
{% endif %}
</div>
<button type="submit" class="submit_btn">Sign Up</button>
<span class="peder"><p>If you already have account<br>Login</p></span>
</form>
and forms.py:
class CustomerSignUpForm(UserCreationForm):
first_name = forms.CharField(required=True)
last_name = forms.CharField(required=True)
email = forms.EmailField(required=True)
username = forms.CharField(max_length=40)
password = forms.CharField(max_length=30)
confirm_password = forms.CharField(max_length=30)
class Meta(UserCreationForm.Meta):
model = User
#transaction.atomic
def save(self):
user = super().save(commit=False)
user.is_customer = True
user.save()
customer = Customer.objects.create(user=user)
customer.first_name = self.cleaned_data.get('first_name')
customer.last_name = self.cleaned_data.get('last_name')
customer.username = self.cleaned_data.get('username')
customer.email = self.cleaned_data.get('email')
customer.password = self.cleaned_data.get('password')
customer.confirm_password = self.cleaned_data.get('confirm_password')
customer.save()
return user
My model looks like this:
class User(AbstractUser):
is_customer = models.BooleanField(default=False)
is_employee = models.BooleanField(default=False)
# first_name = models.CharField(max_length=100)
# last_name = models.CharField(max_length=100)
signup_confirmation = models.BooleanField(default=False)
class Customer(models.Model):
user = models.OneToOneField(User, on_delete = models.CASCADE, primary_key = True)
first_name = models.CharField(max_length=100, blank=True)
last_name = models.CharField(max_length=100, blank=True)
username = models.CharField(max_length=40, blank=True)
email = models.EmailField(max_length=40, blank=True)
password = models.CharField(max_length=30, blank=True)
confirm_password = models.CharField(max_length=30, blank=True)
So when user clicks submit button on signup form it should save the form and send him an email.
view
class customer_register(CreateView):
model = User
form_class = CustomerSignUpForm
template_name = 'authentication/customer_register.html'
def form_valid(self, form):
user = form.save()
# current_site = get_current_site(request)
current_site = '127.0.0.1:8000'
subject = 'Please Activate Your Account'
message = render_to_string('authentication/email/activation_request.html', {
'user': user,
'domain': current_site,
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'token': account_activation_token.make_token(user),
})
send_mail(
subject,
message,
'from#example.com',
['to#example.com'],
fail_silently=False,
)
return redirect('/')
But when I click submit button on my page nothing happens. In my terminal I do get [13/Sep/2022 08:18:39] "POST /accounts/customer_register/ HTTP/1.1" 200 9660 but user is not created and email is not sent. Could someone explain why this is happening and present the solution? Thanks:)
First of all.
We need to install few dependencies.
1. pip install django-crispy-forms
2. add 'crispy_forms', to your INSTALLED_APPS in your projects settings.py
3. add CRISPY_TEMPLATE_PACK = 'bootstrap4' to your settings.py
authentication/customer_register.html
We simplify the form through crispy forms that gives us a bootstrap 4 result.
{% load crispy_forms_tags %}
<form class="login_form" method="post" novalidate>
{% csrf_token %}
{% crispy form %}
<button type="submit" class="btn btn-success mt-3 float-end">Submit</button>
</form>
forms.py
We create a modelForm taking the model User and its fields as Meta:
from django import forms
class CustomerSignUpForm(forms.ModelForm):
class Meta:
model = User
fields = ['first_name', 'last_name', 'email',
'username', 'password', 'confirm_password']
views.py
#The generic view CreateView Polymorphism already benefits of the post method that will save the user
from django.views.generic import CreateView
from.forms import CustomerSignUpForm
class CustomerRegisterCreateView(CreateView):
model = User
form_class = CustomerSignUpForm
template_name = 'authentication/customer_register.html'
urls.py
We create a path so we can link it to a URL with not forgetting the .as_view() as it is a class based view ( function based views do not require this )
from .views import (
CustomerRegisterCreateView,
)
urlpatterns = [
path('customer-register/', CustomerRegisterCreateView.as_view(), name="customer-register"),
]
models.py
Once a user is created, we use a signal that will trigger on user creation.
from django.db.models.signals import post_save
def User_receiver(sender, instance, created, *args, **kwargs):
if created:
print('we went thought the User signal !')
subject = "Welcome"
email_template_name = "authentication/Register-email.txt"
user = User.objects.get(username=instance.username)
c = {
'username': user,
}
email = instance.email
email_1 = render_to_string(email_template_name, c)
send_mail(subject, email_1, 'your_email',
[email], fail_silently=False)
'''
post_save.connect(User_receiver, sender=User)
In my django project I have a form VisitorRegForm which collects scanned_id and body_temp and submits data to my database table ClinicalData, since the current user is already logged in, how can I make this form to also be able grab current logged in user's username and email (Note: username and email were both created from the built-in django User model) and submit these four items: 'scanned_id', 'body_temp', 'username', 'email' into the database table ClinicalData?
Don't mind the missing details and inports, the form works and am able to submit 'scanned_id', 'body_temp'. Help me on the easiest way I will be able to submit these four items: 'scanned_id', 'body_temp', 'username', 'email' looking at the details shown in the files below:
Where should it be easier to achieve this; in the views.py or the template file?
forms.py
class VisitorRegForm(UserCreationForm):
class Meta:
model = User
fields = ['username', 'email', 'password1', 'password2']
class ScannerForm(ModelForm):
class Meta:
model = ClinicalData
fields = ['scanned_id', 'body_temp']
models.py
class ClinicalData(models.Model):
...
scanned_id = models.CharField(verbose_name="Scanned ID", max_length=50, null=True)
body_temp = models.DecimalField(verbose_name="Body Temperature", max_digits=3, decimal_places=1, null=True)
username = models.CharField(verbose_name="Facility Name", max_length=200, null=True)
email = models.EmailField(verbose_name="Visitor Email", max_length=200, null=True)
...
views.py
Am assuming I might need like two variables here in the views that should help me like the ones i've commented out, if it should start from here, help me how it should succeed:
#login_required(login_url='login')
def scanEnter(request):
#grab_username = function_to_grab_current_logged_in_username_HELP_ME_HERE
#grab_email = function_to_grab_current_logged_in_user_email_HELP_ME_HERE
form = ScannerForm(request.POST)
if request.method == 'POST':
form = ScannerForm(request.POST)
if form.is_valid():
form.save()
return redirect('scanenter')
context = {'form': form}
return render(request, 'scan_enter_fac.html', context)
scan_enter_fac.html
<form action="" method="post">
{% csrf_token %}
<div class="">scanned_id<input type="text" id="multiple" class="form-control" placeholder="or Type ID here; e.g: ACCTS-147" name="scanned_id"></div>
<div class="">body_temp<input type="text" class="form-control" placeholder="e.g: 36.5" name="body_temp"></div>
<button type="submit" class="btn btn-danger btn-block">Submit</button>
</form>
views.py:
#login_required(login_url='login')
def scanEnter(request):
#grab_username = function_to_grab_current_logged_in_username_HELP_ME_HERE
#grab_email = function_to_grab_current_logged_in_user_email_HELP_ME_HERE
form = ScannerForm(request.POST)
if request.method == 'POST':
form = ScannerForm(request.POST)
if form.is_valid():
form = form.save(commit=False)
form.username = request.user.username #new
form.email = request.user.email #new
form.save()
return redirect('scanenter')
context = {'form': form}
return render(request, 'scan_enter_fac.html', context)
scan_enter_fac.html
<form action="" method="post">
{% csrf_token %}
<div class="">{{ form.scanned_id }}</div>
<div class="">{{ form.body_temp }}</div>
<button type="submit" class="btn btn-danger btn-block">Submit</button>
</form>
I have two models in for, one has member details and the other is the user model, what i want is to use the foreign key of member model in User model when creating a member account.
In a form, when a member name with foreign key is selected, the email field should be pre-populated with value from the members table.
I know ajax can do this asynchronous call to the database but how do i achieve this? thank you.
User Model
class User(AbstractBaseUser , PermissionsMixin):
email = models.EmailField(max_length=255, unique=True, blank=True, null=True)
username = models.CharField(max_length=30, unique=True)
Role = models.CharField(max_length=250, choices=roles, blank=True, null=True)
full_name = models.ForeignKey('Members', on_delete=models.SET_NULL, max_length=100, null=True, blank=True)
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=False)
is_superuser = models.BooleanField(default=False)
Is_View_on_Web = models.CharField(max_length=20, default='Yes', choices=OPTIONS,null=True,blank=True)
USERNAME_FIELD = 'username'
REQUIRED_FILEDS = []
objects = UserManager()
published = PublishedStatusManager()
def __str__(self):
return str(self.full_name)
and Members Model
class Members(models.Model):
First_Name=models.CharField(max_length=100,null=True)
Second_Name=models.CharField(max_length=100,null=True)
Home_Cell=models.CharField(max_length=100, choices=cell,null=True)
Residence=models.CharField(max_length=100,null=True)
Telephone=models.CharField(max_length=100,null=True)
Email=models.CharField(max_length=100,null=True, blank=True)
def __str__(self):
return str(self.First_Name )+ ' ' + str(self.Second_Name)
here is my register.html
<form method="POST">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom">Add New User to the System</legend>
<div class="separator"></div>
<div class="form-group">
{{ form|crispy}}
</div>
</fieldset>
<div class="form-group">
<button class="btn btn-primary" type="submit"> Submit</button>
</div>
</form>
form.py
class RegisterForm(forms.ModelForm):
class Meta:
model = User
fields = ['full_name','email','username','Role','Is_View_on_Web']
this is my proposition after test and it works fine:
form.py => add attribut that will call a JS function defined in your .html
from django.forms import ModelForm, Form
from .models import User
class RegisterForm(ModelForm):
class Meta:
model = User
fields = ['username', 'full_name', 'email', 'Role', 'Is_View_on_Web']
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['full_name'].widget.attrs['onchange'] = "load_email()"
.html: => define the JS function
<body>
<form id = "myform" method="POST">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom">Add New User to the System</legend>
<div class="separator"></div>
<div class="form-group">
{{ form }}
</div>
</fieldset>
<div class="form-group">
<button class="btn btn-primary" type="submit"> Submit</button>
</div>
</form>
</body>
<script>
function load_email()
{
document.getElementById('myform').action = "/stack/myview";
document.getElementById("myform").submit();
}
</script>
Views.py:=> new view that will look for the email address in the database and return to the template
def myview(request):
form = RegisterForm(request.POST)
if form.is_valid():
db = form.save(commit=False)
db.email = Members.objects.get(id__exact=form['full_name'].value()).Email
form = RegisterForm(instance=db)
content = {'form': form}
return render(request, 'stack/index.html', content)
else:
content = {'form': form}
return render(request, 'stack/index.html', content)
I want to make a register form, that contains user form and user profile form
my table user is from Django auth_user so it will contain primary column like id, user, email, password, started date, etc
and I have user profile form, that creates from forms.py and the model from model.py here, it has FK user_id which connected to ID in auth_user
the problem is, when I insert the data, it always said this field required, even though I already insert all the column
here's the code
forms.py
class UserForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'form-control'}))
username = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}))
email = forms.CharField(widget=forms.EmailInput(attrs={'class': 'form-control'}))
class Meta():
model = User
fields = ('username', 'email', 'password')
class UserProfileInfoForm(forms.ModelForm):
ROLE_1 = 'Business Analyst'
ROLE_2 = 'Manager'
ROLE_3 = 'Segment Manager'
ROLE_4 = 'Admin'
ROLE_CHOICES = (
(ROLE_1, u"Business Analyst"),
(ROLE_2, u"Manager"),
(ROLE_3, u"Segment Manager"),
(ROLE_4, u"Admin")
)
role = forms.ChoiceField(choices=ROLE_CHOICES, widget=forms.Select(attrs={'class': 'form-control'}))
description = forms.CharField(widget=forms.Textarea(attrs={'class': 'form-control'}))
address = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}))
phone = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}))
cell = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}))
def __init__(self, disable_fields=True, *args, **kwargs):
super().__init__(*args, **kwargs)
if disable_fields:
self.fields['role'].disabled = True
models.py
class UserProfileInfo(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile')
role = models.CharField(max_length=250, blank=True)
description = models.TextField(max_length=250, blank=True)
address = models.CharField(max_length=250, blank=True)
phone = models.CharField(max_length=250, blank=True)
cell = models.CharField(max_length=250, blank=True)
profile_pic = models.ImageField(upload_to='profile_pics', blank=True)
def __str__(self):
return self.user.username
def register(request):
registered = False
if request.method == 'POST':
print("test")
user_form = UserForm(request.POST)
profile_form = UserProfileInfoForm(request.POST)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
user.set_password(user.password)
user.save()
profile = profile_form.save(commit=false)
profile.user = user
if 'profile_pic' in request.FILES:
profile.profile_pic = request.FILES['profile_pic']
profile.save()
registered = True
else:
print(user_form.errors, profile_form.errors)
else:
user_form = UserForm()
profile_form = UserProfileInfoForm(disable_fields=False)
return render(request, 'register.html',
{'user_form': user_form,
'profile_form': profile_form,
'registered': registered})
html
<section id="main-content">
<section class="wrapper">
<h3><i class="fa fa-angle-right"></i>Register User</h3>
<!-- row -->
<!-- FORM VALIDATION -->
<div class="row mt">
<div class="col-lg-12">
<div class="form-panel">
<div class=" form">
{% load staticfiles %}
{% block body_block %}
{% if registered %}
<h1>Thank you for registering!</h1>
{% else %}
<form class=" form-horizontal style-form" id="commentForm" enctype="multipart/form-data" method="POST" action="">
{% csrf_token %}
{{ user_form.as_p}}
{{ profile_form.as_p }}
<button class="btn btn-theme" type="submit" style="height:50px;width:200px;" value="Register">Register</button>
</form>
{% endif %}
</div>
</div>
{% endblock %}
</div>
</div>
<!-- /form-panel -->
</div>
<!-- /col-lg-12 -->
</div>
<!-- /row -->
</section>
</section>
can someone help me? i already try some way like remove the profile_form.isvalid() in the if condition, and it goes to the next step, but it is error ORA-01400: cannot insert NULL into ("ICB"."POLLS_USERPROFILEINFO"."USER_ID") which user_id is the fk
at first .. I make this module and it works fine, but 1 month later it errors, and I didn't change any code
Try edit this section in your html:
action="your_url_here"
I have been trying to do my login and register on the sane template, but have been having issues with it. please i need some help. Below are my codes:
views.py:
def register_user(request):
if request.user.is_authenticated():
return redirect('home')
if request.method == 'POST':
rform = RegistrationForm(request.POST)
if rform.is_valid():
user = User.objects.create_user()
user.username = rform.cleaned_data['email']
user.set_password(rform.cleaned_data['password'])
user.first_name = rform.cleaned_data['first_name']
user.last_name = rform.cleaned_data['last_name']
user.email = rform.cleaned_data['email']
user.gender = rform.cleaned_data['gender']
user.save()
loggedin_user = authenticate(email = rform.cleaned_data['email'],
password = rform.cleaned_data['password'])
if user is not None:
login(request, loggedin_user)
return redirect('home')
else:
return render(request, 'accounts/access.html', {'rform': RegistrationForm()})
else:
return render(request, 'accounts/access.html', {'rform': RegistrationForm()})
else:
form = RegistrationForm()
return render(request, 'accounts/access.html', {'rform':form})
def login_now(request, *args, **kwargs):
if request.user.is_authenticated():
return redirect('home')
if request.method == "POST":
form = AuthenticationForm(request.POST)
if form.is_valid():
username = form.cleaned_data['email']
password = form.cleaned_data['password']
user = authenticate(username = form.cleaned_data['email'], password = password)
if user is not None:
login(request, user)
return redirect('home')
else:
return render(request, 'accounts/access.html', {'form': AuthenticationForm(), 'rform':RegistrationForm(), 'next':reverse_lazy('home')})
else:
return render(request, 'accounts/access.html', {'form': AuthenticationForm(), 'rform':RegistrationForm(), 'next':reverse_lazy('home')})
else:
return render(request, 'accounts/access.html', {'form': AuthenticationForm(), 'rform':RegistrationForm(), 'next':reverse_lazy('home')})
forms.py:
CHOICES = [
('Male', "Male"),
('Female', "Female"),
]
class RegistrationForm(forms.Form):
first_name = forms.CharField(max_length=25, widget=forms.TextInput(attrs={'placeholder': 'First name'}))
last_name = forms.CharField(max_length=25, widget=forms.TextInput(attrs={'placeholder': 'Last name'}))
email = forms.EmailField(max_length=50, widget=forms.TextInput(attrs={'placeholder': 'Email'}))
password = forms.CharField(max_length=25, widget=forms.PasswordInput(attrs={'placeholder': 'Password'}))
password1 = forms.CharField(max_length=25, widget=forms.PasswordInput(attrs={'placeholder': 'Password Confirm'}), label=("Re-type Password"))
gender = forms.ChoiceField(choices=CHOICES, widget=forms.RadioSelect(attrs={'placeholder': 'Gender'}))
class Meta:
model = ('User',)
def clean_email(self):
data = self.cleaned_data['email']
if User.objects.get(email=data):
raise forms.ValidationError('A user with this email already exist. You may recover the password with a password reset')
return data
def clean_password(self):
password = self.cleaned_data.get("password")
password1 = self.cleaned_data.get("password1")
if password1 and password and password1 != password:
raise forms.ValidationError(
self.error_messages['password_mismatch'],
code='password_mismatch',
)
return password
access.html:
<div id = 'signup'>
<form id="post-form" action="{% url 'register' %}" method="POST">
{% csrf_token %}
<h3>REGISTER</h3>
<div>
{%for field in rform%}
<div style="margin-top:10px;">
{{field.label_tag}}<br/> {{field}}
{%if field.errors%} <br/>{{field.errors}} {%endif%}
</div>
{%endfor%}
</div>
<input type="submit" value="Register" class='sub' id='register'/>
</div>
<div id='login'>
{% if form.errors %}
{{ form.non_field_errors}}
{% endif %}
<form action='{% url 'login' %}' method='post' id ='signIn'>
{% csrf_token %}
<h3>SIGN IN</h3>
<p><label>Email:</label><br/>
{{ rform.email }}
{{ rform.email.errors }}</p>
<p><label>Password:</label><br/>
{{ rform.password }}
{{ rform.password.errors }}</p>
<p><input type="submit" value="login" id='submit' class='sub' /><br>
<input type="hidden" name="next" value="{% url 'home' %}" />
</form>
</div>
I try to register with the above and all i always get, is a redirection, please i need help.
Thanks in advance.
Please note, i extended the user profile that's why i have the gender in my registration form.
In your code, you are not comparing the right parameters
loggedin_user = authenticate(email = rform.cleaned_data['email'],
password = rform.cleaned_data['password'])
if user is not None:
login(request, loggedin_user)
return redirect('home')
You are checking an None variable, not the one returned by the authenticate ! if loggedin_user is not None is the correct check.
Check the example on the official doc.
You need to send the validated form rform so you can show the feedback (errors) to the user, you are sending a new form after the validation RegistrationForm()!
Also try to identify the source of the problem, you are posting your hole code but you don't know where the problem comes from, at least do some debugging ;) !