You have this statement:
user = User.objects.create_user(username=username, email=email, password =
password)
Just before this statement, you need to insert a statement that will enable you
to examine the value of the "username" statement. Something like this:
print(username)
user = User.objects.create_user(username=username, email=email, password =
password)
This might or not might work properly with Django. What most Python programmers
would do instead is this:
import pdb; pdb.set_trace()
user = User.objects.create_user(username=username, email=email, password =
password)
but for that you need to know how to use pdb. It's quite simple though tricky at
first. Eventually you will need to learn it, however, so now would be a good
time. Search the web.
Regards,
Antonis
Antonis Christofides
+30-6979924665 (mobile)
On 22/02/2022 19.01, Raj wrote:
I am trying to create register form access in django, but i am getting this*"
ValueError at /registerThe given username must be set" error.
*
Kindly help me how can I fix this bug.
please.
*here is the code of the views.py file.--->*
from msilib.schema import Feature
from pyexpat.errors import messages
from django.shortcuts import render, redirect
from django.contrib.auth.models import User, auth
from django.contrib import messages
from django.http import HttpResponse
from .models import Feature
# Create your views here.
def index(request):
return render(request,'index.html',{'features': features})
#=-------register function-------
def register(request):
if request.method == 'POST':
username = request.POST.get('username')
email = request.POST.get('email')
password = request.POST.get('password')
password2 = request.POST.get('password2')
# username = request.POST['username']
# email = request.POST['email']
# password = request.POST['password']
# password2 = request.POST['password2']
if password == password2:
if User.objects.filter(email = email).exists():
messages.info(request, 'Email already has been used!')
return redirect('register')
elif User.objects.filter(username= username).exists():
messages.info(request, 'Username already exist')
return redirect('register')
else:
user = User.objects.create_user(username=username,
email=email, password = password)
user.save();
print("User created")
return redirect('login') #check
else:
messages.info(request, 'Incorrect password')
return redirect('register')
else:
return render(request, 'register.html')
def login(request):
if request.method == 'POST':
# username = request.POST['username']
# password = request.POST['password']
username = request.POST.get('username')
password = request.POST.get('password')
user = auth.authenticate(username = username, password = password)
if user is not None:
auth.login(request, user)
return redirect('/')
else:
messages.info(request,'Credential Invalid')
return redirect('login')
else:
return render(request, 'login.html')
*here is the SS of the error*Screenshot (75).png
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/c7bcf4b5-f8e7-4f84-97df-02e4655e42f1n%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/c7bcf4b5-f8e7-4f84-97df-02e4655e42f1n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/cdfef3b3-37b4-801d-c53c-85d8176e3025%40antonischristofides.com.