Hi, 
Thanks for the response, I have tried to print the username before creating 
the user, but it did not work. I have also tried to use pdb that also 
didn't work.

How to do it can give proper instructions??
I have searched about it on google but have not received any relevant 
answer.

On Wednesday, 23 February 2022 at 12:26:42 UTC+5:30 [email protected] 
wrote:

> 7008080545 DM .
>
> On Wed, 23 Feb 2022, 12:22 pm Antonis Christofides, <
> [email protected]> wrote:
>
>> 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 <+30%20697%20992%204665> (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*[image: 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
>>  
>> <https://groups.google.com/d/msgid/django-users/cdfef3b3-37b4-801d-c53c-85d8176e3025%40antonischristofides.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/f083d61d-7207-412a-acdd-a3c90be80d7bn%40googlegroups.com.

Reply via email to