Re: dlango MultiValueDictKeyError

2022-08-10 Thread Lakshyaraj Dash
You may have missed the name attribute in your form input

On Wed, Aug 10, 2022, 19:18 Benji Zachariah  wrote:

> I am getting an below error in module GET and POST
>
> MultiValueDictKeyError at /user-details
>
> 'Name'
>
> Request Method:GET
> Request URL:http://127.0.0.1:8000/user-details
> Django Version:4.0.6
> Exception Type:MultiValueDictKeyError
> Exception Value:
> 'Name'
> Exception Location:
>  
> C:\Users\Megha\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\datastructures.py,
> line 86, in __getitem__
> Python Executable:
>  C:\Users\Megha\AppData\Local\Programs\Python\Python310\python.exe
> Python Version:3.10.5
> Python Path:
> ['C:\\Users\\Megha\\django\\form',
>
>  
> 'C:\\Users\\Megha\\AppData\\Local\\Programs\\Python\\Python310\\python310.zip',
>  'C:\\Users\\Megha\\AppData\\Local\\Programs\\Python\\Python310\\DLLs',
>  '
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d62d078b-87b7-40c3-82fe-ad203e724357n%40googlegroups.com
> 
> .
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAF7qQgAL35D70H7Z7rediJO_j%2BWzr0EYCnN1XkFUHbnmB6aF6Q%40mail.gmail.com.


Re: dlango MultiValueDictKeyError

2022-08-10 Thread Abdul Qoyyuum
What have you tried to do? Is there a particular key that causes this? Can
you share the full stack traceback please?

On Wed, Aug 10, 2022 at 9:49 PM Benji Zachariah 
wrote:

> I am getting an below error in module GET and POST
>
> MultiValueDictKeyError at /user-details
>
> 'Name'
>
> Request Method:GET
> Request URL:http://127.0.0.1:8000/user-details
> Django Version:4.0.6
> Exception Type:MultiValueDictKeyError
> Exception Value:
> 'Name'
> Exception Location:
>  
> C:\Users\Megha\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\datastructures.py,
> line 86, in __getitem__
> Python Executable:
>  C:\Users\Megha\AppData\Local\Programs\Python\Python310\python.exe
> Python Version:3.10.5
> Python Path:
> ['C:\\Users\\Megha\\django\\form',
>
>  
> 'C:\\Users\\Megha\\AppData\\Local\\Programs\\Python\\Python310\\python310.zip',
>  'C:\\Users\\Megha\\AppData\\Local\\Programs\\Python\\Python310\\DLLs',
>  '
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d62d078b-87b7-40c3-82fe-ad203e724357n%40googlegroups.com
> 
> .
>


-- 
Abdul Qoyyuum Bin Haji Abdul Kadir
HP No: +673 720 8043

-- 
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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA3DN%3DV43KFnKTM92wBj5L5z9f92WmS0NcRzjkaOrird8Xr0iw%40mail.gmail.com.


dlango MultiValueDictKeyError

2022-08-10 Thread Benji Zachariah
I am getting an below error in module GET and POST

MultiValueDictKeyError at /user-details

'Name'

Request Method:GET
Request URL:http://127.0.0.1:8000/user-details
Django Version:4.0.6
Exception Type:MultiValueDictKeyError
Exception Value:
'Name'
Exception Location:   
 
C:\Users\Megha\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\datastructures.py,
 
line 86, in __getitem__
Python Executable:   
 C:\Users\Megha\AppData\Local\Programs\Python\Python310\python.exe
Python Version:3.10.5
Python Path:
['C:\\Users\\Megha\\django\\form',
 'C:\\Users\\Megha\\AppData\\Local\\Programs\\Python\\Python310\\python310.zip',
 'C:\\Users\\Megha\\AppData\\Local\\Programs\\Python\\Python310\\DLLs',
 '

-- 
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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d62d078b-87b7-40c3-82fe-ad203e724357n%40googlegroups.com.


Re: dlango MultiValueDictKeyError

2019-08-07 Thread Ajeet Kumar Gupt
Hi,

Problem was in my code I was using the request.POST['username'] instead of
request.POST.get('username')

You have given the solutions and the same I have implemented.

Once again thanks to you if any issues let you know.

*Actually, I am very new in Django hardly 1 week back started. This is my
first project to start for the learning purpose and I try to implement a
document management system with the workflow approval process.  I need your
support and help while developing the application. Once the design part
completed will share with you.*

def login_view(request):
templates = 'welcome.html'
username = request.POST.get('username')
password = request.POST.get('pass')
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
return render(request, templates ,{'user' : user  })
else:
#return redirect('welcome.html')
messages.error(request, 'Login Failed! Invalid username and password.')
return render(request, 'login.html',{'user' : user  })














On Tue, Aug 6, 2019 at 8:55 PM DPM  wrote:

> Hey Ajit,
> Its Great.
> Can you please tell us what was the problem?
>
> On Tue, 6 Aug, 2019, 1:07 PM Ajeet Kumar Gupt, 
> wrote:
>
>> Hi,
>>
>> Thank you very much now issues have been resolved.
>>
>>
>>
>> On Mon, Aug 5, 2019 at 6:14 PM Sipum Mishra  wrote:
>>
>>> Hey Ajit,
>>>
>>> This error comes when You are trying to get username, passwords from the
>>> form.
>>> It is due to the below reason -
>>>
>>> In Login,
>>> You are using -> request.POST['username'] which will raise a KeyError
>>> exception if 'username' is not in request.POST.
>>>
>>> Instead use -> request.POST.get('username') which will return None if '
>>> username' is not in request.POST.
>>>
>>> Additionally, .get allows you to provide an additional parameter of a
>>> default value which is returned if the key is not in the dictionary.
>>>
>>> For example, request.POST.get('username', 'mydefaultvalue')
>>>
>>> Hope this helps. If any concern then let us know.
>>>
>>> On Mon, 5 Aug 2019 at 15:47, Ajeet Kumar Gupt 
>>> wrote:
>>>
 Dear Team,

 I am developing custom registration and login page for end-user but
 getting the below error. Please find the views.py code also in the trail.


 *MultiValueDictKeyError at /login/*

 'username'

 Request Method: GET
 Request URL: http://127.0.0.1:8000/login/
 Django Version: 2.2.3
 Exception Type: MultiValueDictKeyError
 Exception Value:

 'username'

 Exception Location: 
 C:\Python\Python37\lib\site-packages\django\utils\datastructures.py
 in __getitem__, line 80
 Python Executable: C:\Python\Python37\python.exe
 Python Version: 3.7.3

 --
 *Views.py*
 **

 rom django.shortcuts import render
 from django.contrib.auth.models import User
 from django.http import HttpResponseRedirect
 from .forms import RegisterForm
 from django.conf import settings
 from django.shortcuts import redirect
 from django.contrib.auth.decorators import login_required
 from django.contrib import messages
 from django.contrib.auth import authenticate,login
 from django.contrib import auth
 from django.core.exceptions import ObjectDoesNotExist


 def user_register(request):
 # if this is a POST request we need to process the form data
 template = 'mymodule/register.html'
# template = 'index.html'
 if request.method == 'POST':
 # create a form instance and populate it with data from the 
 request:
 form = RegisterForm(request.POST)
 # check whether it's valid:
 if form.is_valid():
 if 
 User.objects.filter(username=form.cleaned_data['username']).exists():
 return render(request, template, {
 'form': form,
 'error_message': 'Username already exists.'
 })
 elif 
 User.objects.filter(email=form.cleaned_data['email']).exists():
 return render(request, template, {
 'form': form,
 'error_message': 'Email already exists.'
 })
 elif form.cleaned_data['password'] != 
 form.cleaned_data['password_repeat']:
 return render(request, template, {
 'form': form,
 'error_message': 'Passwords do not match.'
 })
 else:
 # Create the user:
 user = User.objects.create_user(
 form.cleaned_data['username'],
 form.cleaned_data['email'],
 form.cleaned_data['password']
 )
 

Re: dlango MultiValueDictKeyError

2019-08-06 Thread DPM
Hey Ajit,
Its Great.
Can you please tell us what was the problem?

On Tue, 6 Aug, 2019, 1:07 PM Ajeet Kumar Gupt, 
wrote:

> Hi,
>
> Thank you very much now issues have been resolved.
>
>
>
> On Mon, Aug 5, 2019 at 6:14 PM Sipum Mishra  wrote:
>
>> Hey Ajit,
>>
>> This error comes when You are trying to get username, passwords from the
>> form.
>> It is due to the below reason -
>>
>> In Login,
>> You are using -> request.POST['username'] which will raise a KeyError
>> exception if 'username' is not in request.POST.
>>
>> Instead use -> request.POST.get('username') which will return None if '
>> username' is not in request.POST.
>>
>> Additionally, .get allows you to provide an additional parameter of a
>> default value which is returned if the key is not in the dictionary.
>>
>> For example, request.POST.get('username', 'mydefaultvalue')
>>
>> Hope this helps. If any concern then let us know.
>>
>> On Mon, 5 Aug 2019 at 15:47, Ajeet Kumar Gupt 
>> wrote:
>>
>>> Dear Team,
>>>
>>> I am developing custom registration and login page for end-user but
>>> getting the below error. Please find the views.py code also in the trail.
>>>
>>>
>>> *MultiValueDictKeyError at /login/*
>>>
>>> 'username'
>>>
>>> Request Method: GET
>>> Request URL: http://127.0.0.1:8000/login/
>>> Django Version: 2.2.3
>>> Exception Type: MultiValueDictKeyError
>>> Exception Value:
>>>
>>> 'username'
>>>
>>> Exception Location: 
>>> C:\Python\Python37\lib\site-packages\django\utils\datastructures.py
>>> in __getitem__, line 80
>>> Python Executable: C:\Python\Python37\python.exe
>>> Python Version: 3.7.3
>>>
>>> --
>>> *Views.py*
>>> **
>>>
>>> rom django.shortcuts import render
>>> from django.contrib.auth.models import User
>>> from django.http import HttpResponseRedirect
>>> from .forms import RegisterForm
>>> from django.conf import settings
>>> from django.shortcuts import redirect
>>> from django.contrib.auth.decorators import login_required
>>> from django.contrib import messages
>>> from django.contrib.auth import authenticate,login
>>> from django.contrib import auth
>>> from django.core.exceptions import ObjectDoesNotExist
>>>
>>>
>>> def user_register(request):
>>> # if this is a POST request we need to process the form data
>>> template = 'mymodule/register.html'
>>># template = 'index.html'
>>> if request.method == 'POST':
>>> # create a form instance and populate it with data from the request:
>>> form = RegisterForm(request.POST)
>>> # check whether it's valid:
>>> if form.is_valid():
>>> if 
>>> User.objects.filter(username=form.cleaned_data['username']).exists():
>>> return render(request, template, {
>>> 'form': form,
>>> 'error_message': 'Username already exists.'
>>> })
>>> elif 
>>> User.objects.filter(email=form.cleaned_data['email']).exists():
>>> return render(request, template, {
>>> 'form': form,
>>> 'error_message': 'Email already exists.'
>>> })
>>> elif form.cleaned_data['password'] != 
>>> form.cleaned_data['password_repeat']:
>>> return render(request, template, {
>>> 'form': form,
>>> 'error_message': 'Passwords do not match.'
>>> })
>>> else:
>>> # Create the user:
>>> user = User.objects.create_user(
>>> form.cleaned_data['username'],
>>> form.cleaned_data['email'],
>>> form.cleaned_data['password']
>>> )
>>> user.first_name = form.cleaned_data['first_name']
>>> user.last_name = form.cleaned_data['last_name']
>>> user.phone_number = form.cleaned_data['phone_number']
>>> user.save()
>>> return redirect('index.html')
>>> # Login the user
>>> #login(request, user)
>>> #def user_login(request):
>>> # redirect to accounts page:
>>> #return render(request, '/login.html')
>>># return HttpResponseRedirect(return, '/login.html')
>>># No post data availabe, let's just show the page.
>>> else:
>>> form = RegisterForm()
>>> return render(request, template, {'form': form})
>>>
>>>
>>>
>>>
>>>
>>> def login_view(request):
>>> username = request.POST['username']
>>> password = request.POST['pass']
>>> users = authenticate(request, username=username, password=password)
>>> if users is not None:
>>> login(request, users)
>>> return redirect('welcome.html')
>>> else:
>>> return redirect('index.html')
>>>
>>>
>>>
>>> def logout(request):
>>> auth.logout(request)
>>> return render(request, 'login.html')
>>>
>>>
>>>
>>>
>>> 

Re: dlango MultiValueDictKeyError

2019-08-06 Thread Ajeet Kumar Gupt
Hi,

Thank you very much now issues have been resolved.



On Mon, Aug 5, 2019 at 6:14 PM Sipum Mishra  wrote:

> Hey Ajit,
>
> This error comes when You are trying to get username, passwords from the
> form.
> It is due to the below reason -
>
> In Login,
> You are using -> request.POST['username'] which will raise a KeyError
> exception if 'username' is not in request.POST.
>
> Instead use -> request.POST.get('username') which will return None if '
> username' is not in request.POST.
>
> Additionally, .get allows you to provide an additional parameter of a
> default value which is returned if the key is not in the dictionary.
>
> For example, request.POST.get('username', 'mydefaultvalue')
>
> Hope this helps. If any concern then let us know.
>
> On Mon, 5 Aug 2019 at 15:47, Ajeet Kumar Gupt 
> wrote:
>
>> Dear Team,
>>
>> I am developing custom registration and login page for end-user but
>> getting the below error. Please find the views.py code also in the trail.
>>
>>
>> *MultiValueDictKeyError at /login/*
>>
>> 'username'
>>
>> Request Method: GET
>> Request URL: http://127.0.0.1:8000/login/
>> Django Version: 2.2.3
>> Exception Type: MultiValueDictKeyError
>> Exception Value:
>>
>> 'username'
>>
>> Exception Location: 
>> C:\Python\Python37\lib\site-packages\django\utils\datastructures.py
>> in __getitem__, line 80
>> Python Executable: C:\Python\Python37\python.exe
>> Python Version: 3.7.3
>>
>> --
>> *Views.py*
>> **
>>
>> rom django.shortcuts import render
>> from django.contrib.auth.models import User
>> from django.http import HttpResponseRedirect
>> from .forms import RegisterForm
>> from django.conf import settings
>> from django.shortcuts import redirect
>> from django.contrib.auth.decorators import login_required
>> from django.contrib import messages
>> from django.contrib.auth import authenticate,login
>> from django.contrib import auth
>> from django.core.exceptions import ObjectDoesNotExist
>>
>>
>> def user_register(request):
>> # if this is a POST request we need to process the form data
>> template = 'mymodule/register.html'
>># template = 'index.html'
>> if request.method == 'POST':
>> # create a form instance and populate it with data from the request:
>> form = RegisterForm(request.POST)
>> # check whether it's valid:
>> if form.is_valid():
>> if 
>> User.objects.filter(username=form.cleaned_data['username']).exists():
>> return render(request, template, {
>> 'form': form,
>> 'error_message': 'Username already exists.'
>> })
>> elif 
>> User.objects.filter(email=form.cleaned_data['email']).exists():
>> return render(request, template, {
>> 'form': form,
>> 'error_message': 'Email already exists.'
>> })
>> elif form.cleaned_data['password'] != 
>> form.cleaned_data['password_repeat']:
>> return render(request, template, {
>> 'form': form,
>> 'error_message': 'Passwords do not match.'
>> })
>> else:
>> # Create the user:
>> user = User.objects.create_user(
>> form.cleaned_data['username'],
>> form.cleaned_data['email'],
>> form.cleaned_data['password']
>> )
>> user.first_name = form.cleaned_data['first_name']
>> user.last_name = form.cleaned_data['last_name']
>> user.phone_number = form.cleaned_data['phone_number']
>> user.save()
>> return redirect('index.html')
>> # Login the user
>> #login(request, user)
>> #def user_login(request):
>> # redirect to accounts page:
>> #return render(request, '/login.html')
>># return HttpResponseRedirect(return, '/login.html')
>># No post data availabe, let's just show the page.
>> else:
>> form = RegisterForm()
>> return render(request, template, {'form': form})
>>
>>
>>
>>
>>
>> def login_view(request):
>> username = request.POST['username']
>> password = request.POST['pass']
>> users = authenticate(request, username=username, password=password)
>> if users is not None:
>> login(request, users)
>> return redirect('welcome.html')
>> else:
>> return redirect('index.html')
>>
>>
>>
>> def logout(request):
>> auth.logout(request)
>> return render(request, 'login.html')
>>
>>
>>
>>
>> *Thanks & Regards*
>> Ajeet Kumar Gupt
>> +91-9311232332
>>
>> --
>> 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 

Re: dlango MultiValueDictKeyError

2019-08-05 Thread DPM
Hey Vishal,

I don't think this error comes for what you told. The error raises for
which I v mentioned above.

And I agree with u as that is also have to do. As he did import auth so
need to write auto.authentication.


On Mon, 5 Aug, 2019, 8:54 PM vishal singh, 
wrote:

>  //users = authenticate(request, username=username, password=password)
>
> you have to use Auth keyword to remove this exception as right now it is
> treated as a dict.
>
>  users = Auth.authenticate(request, username=username, password=password)
>
> On Mon, 5 Aug 2019 at 15:46, Ajeet Kumar Gupt 
> wrote:
>
>> Dear Team,
>>
>> I am developing custom registration and login page for end-user but
>> getting the below error. Please find the views.py code also in the trail.
>>
>>
>> *MultiValueDictKeyError at /login/*
>>
>> 'username'
>>
>> Request Method: GET
>> Request URL: http://127.0.0.1:8000/login/
>> Django Version: 2.2.3
>> Exception Type: MultiValueDictKeyError
>> Exception Value:
>>
>> 'username'
>>
>> Exception Location: 
>> C:\Python\Python37\lib\site-packages\django\utils\datastructures.py
>> in __getitem__, line 80
>> Python Executable: C:\Python\Python37\python.exe
>> Python Version: 3.7.3
>>
>> --
>> *Views.py*
>> **
>>
>> rom django.shortcuts import render
>> from django.contrib.auth.models import User
>> from django.http import HttpResponseRedirect
>> from .forms import RegisterForm
>> from django.conf import settings
>> from django.shortcuts import redirect
>> from django.contrib.auth.decorators import login_required
>> from django.contrib import messages
>> from django.contrib.auth import authenticate,login
>> from django.contrib import auth
>> from django.core.exceptions import ObjectDoesNotExist
>>
>>
>> def user_register(request):
>> # if this is a POST request we need to process the form data
>> template = 'mymodule/register.html'
>># template = 'index.html'
>> if request.method == 'POST':
>> # create a form instance and populate it with data from the request:
>> form = RegisterForm(request.POST)
>> # check whether it's valid:
>> if form.is_valid():
>> if 
>> User.objects.filter(username=form.cleaned_data['username']).exists():
>> return render(request, template, {
>> 'form': form,
>> 'error_message': 'Username already exists.'
>> })
>> elif 
>> User.objects.filter(email=form.cleaned_data['email']).exists():
>> return render(request, template, {
>> 'form': form,
>> 'error_message': 'Email already exists.'
>> })
>> elif form.cleaned_data['password'] != 
>> form.cleaned_data['password_repeat']:
>> return render(request, template, {
>> 'form': form,
>> 'error_message': 'Passwords do not match.'
>> })
>> else:
>> # Create the user:
>> user = User.objects.create_user(
>> form.cleaned_data['username'],
>> form.cleaned_data['email'],
>> form.cleaned_data['password']
>> )
>> user.first_name = form.cleaned_data['first_name']
>> user.last_name = form.cleaned_data['last_name']
>> user.phone_number = form.cleaned_data['phone_number']
>> user.save()
>> return redirect('index.html')
>> # Login the user
>> #login(request, user)
>> #def user_login(request):
>> # redirect to accounts page:
>> #return render(request, '/login.html')
>># return HttpResponseRedirect(return, '/login.html')
>># No post data availabe, let's just show the page.
>> else:
>> form = RegisterForm()
>> return render(request, template, {'form': form})
>>
>>
>>
>>
>>
>> def login_view(request):
>> username = request.POST['username']
>> password = request.POST['pass']
>> users = authenticate(request, username=username, password=password)
>> if users is not None:
>> login(request, users)
>> return redirect('welcome.html')
>> else:
>> return redirect('index.html')
>>
>>
>>
>> def logout(request):
>> auth.logout(request)
>> return render(request, 'login.html')
>>
>>
>>
>>
>> *Thanks & Regards*
>> Ajeet Kumar Gupt
>> +91-9311232332
>>
>> --
>> 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 django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CA%2BTqRsvD7P8Mk4RCUUg-5%3DYTE7PjBnHyJA%3DVZowGgGoYQnyNKw%40mail.gmail.com
>> 

Re: dlango MultiValueDictKeyError

2019-08-05 Thread Grace Nyokabi
what error did you get?

On Mon, 5 Aug 2019 at 13:16, Ajeet Kumar Gupt 
wrote:

> Dear Team,
>
> I am developing custom registration and login page for end-user but
> getting the below error. Please find the views.py code also in the trail.
>
>
> *MultiValueDictKeyError at /login/*
>
> 'username'
>
> Request Method: GET
> Request URL: http://127.0.0.1:8000/login/
> Django Version: 2.2.3
> Exception Type: MultiValueDictKeyError
> Exception Value:
>
> 'username'
>
> Exception Location: 
> C:\Python\Python37\lib\site-packages\django\utils\datastructures.py
> in __getitem__, line 80
> Python Executable: C:\Python\Python37\python.exe
> Python Version: 3.7.3
>
> --
> *Views.py*
> **
>
> rom django.shortcuts import render
> from django.contrib.auth.models import User
> from django.http import HttpResponseRedirect
> from .forms import RegisterForm
> from django.conf import settings
> from django.shortcuts import redirect
> from django.contrib.auth.decorators import login_required
> from django.contrib import messages
> from django.contrib.auth import authenticate,login
> from django.contrib import auth
> from django.core.exceptions import ObjectDoesNotExist
>
>
> def user_register(request):
> # if this is a POST request we need to process the form data
> template = 'mymodule/register.html'
># template = 'index.html'
> if request.method == 'POST':
> # create a form instance and populate it with data from the request:
> form = RegisterForm(request.POST)
> # check whether it's valid:
> if form.is_valid():
> if 
> User.objects.filter(username=form.cleaned_data['username']).exists():
> return render(request, template, {
> 'form': form,
> 'error_message': 'Username already exists.'
> })
> elif 
> User.objects.filter(email=form.cleaned_data['email']).exists():
> return render(request, template, {
> 'form': form,
> 'error_message': 'Email already exists.'
> })
> elif form.cleaned_data['password'] != 
> form.cleaned_data['password_repeat']:
> return render(request, template, {
> 'form': form,
> 'error_message': 'Passwords do not match.'
> })
> else:
> # Create the user:
> user = User.objects.create_user(
> form.cleaned_data['username'],
> form.cleaned_data['email'],
> form.cleaned_data['password']
> )
> user.first_name = form.cleaned_data['first_name']
> user.last_name = form.cleaned_data['last_name']
> user.phone_number = form.cleaned_data['phone_number']
> user.save()
> return redirect('index.html')
> # Login the user
> #login(request, user)
> #def user_login(request):
> # redirect to accounts page:
> #return render(request, '/login.html')
># return HttpResponseRedirect(return, '/login.html')
># No post data availabe, let's just show the page.
> else:
> form = RegisterForm()
> return render(request, template, {'form': form})
>
>
>
>
>
> def login_view(request):
> username = request.POST['username']
> password = request.POST['pass']
> users = authenticate(request, username=username, password=password)
> if users is not None:
> login(request, users)
> return redirect('welcome.html')
> else:
> return redirect('index.html')
>
>
>
> def logout(request):
> auth.logout(request)
> return render(request, 'login.html')
>
>
>
>
> *Thanks & Regards*
> Ajeet Kumar Gupt
> +91-9311232332
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CA%2BTqRsvD7P8Mk4RCUUg-5%3DYTE7PjBnHyJA%3DVZowGgGoYQnyNKw%40mail.gmail.com
> 
> .
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAO0cRQkw5NX7FK%2BtpAr5wBXW3Y%3Da06J6E8g%2BVhQTcKShceh25g%40mail.gmail.com.


Re: dlango MultiValueDictKeyError

2019-08-05 Thread vishal singh
 //users = authenticate(request, username=username, password=password)

you have to use Auth keyword to remove this exception as right now it is
treated as a dict.

 users = Auth.authenticate(request, username=username, password=password)

On Mon, 5 Aug 2019 at 15:46, Ajeet Kumar Gupt 
wrote:

> Dear Team,
>
> I am developing custom registration and login page for end-user but
> getting the below error. Please find the views.py code also in the trail.
>
>
> *MultiValueDictKeyError at /login/*
>
> 'username'
>
> Request Method: GET
> Request URL: http://127.0.0.1:8000/login/
> Django Version: 2.2.3
> Exception Type: MultiValueDictKeyError
> Exception Value:
>
> 'username'
>
> Exception Location: 
> C:\Python\Python37\lib\site-packages\django\utils\datastructures.py
> in __getitem__, line 80
> Python Executable: C:\Python\Python37\python.exe
> Python Version: 3.7.3
>
> --
> *Views.py*
> **
>
> rom django.shortcuts import render
> from django.contrib.auth.models import User
> from django.http import HttpResponseRedirect
> from .forms import RegisterForm
> from django.conf import settings
> from django.shortcuts import redirect
> from django.contrib.auth.decorators import login_required
> from django.contrib import messages
> from django.contrib.auth import authenticate,login
> from django.contrib import auth
> from django.core.exceptions import ObjectDoesNotExist
>
>
> def user_register(request):
> # if this is a POST request we need to process the form data
> template = 'mymodule/register.html'
># template = 'index.html'
> if request.method == 'POST':
> # create a form instance and populate it with data from the request:
> form = RegisterForm(request.POST)
> # check whether it's valid:
> if form.is_valid():
> if 
> User.objects.filter(username=form.cleaned_data['username']).exists():
> return render(request, template, {
> 'form': form,
> 'error_message': 'Username already exists.'
> })
> elif 
> User.objects.filter(email=form.cleaned_data['email']).exists():
> return render(request, template, {
> 'form': form,
> 'error_message': 'Email already exists.'
> })
> elif form.cleaned_data['password'] != 
> form.cleaned_data['password_repeat']:
> return render(request, template, {
> 'form': form,
> 'error_message': 'Passwords do not match.'
> })
> else:
> # Create the user:
> user = User.objects.create_user(
> form.cleaned_data['username'],
> form.cleaned_data['email'],
> form.cleaned_data['password']
> )
> user.first_name = form.cleaned_data['first_name']
> user.last_name = form.cleaned_data['last_name']
> user.phone_number = form.cleaned_data['phone_number']
> user.save()
> return redirect('index.html')
> # Login the user
> #login(request, user)
> #def user_login(request):
> # redirect to accounts page:
> #return render(request, '/login.html')
># return HttpResponseRedirect(return, '/login.html')
># No post data availabe, let's just show the page.
> else:
> form = RegisterForm()
> return render(request, template, {'form': form})
>
>
>
>
>
> def login_view(request):
> username = request.POST['username']
> password = request.POST['pass']
> users = authenticate(request, username=username, password=password)
> if users is not None:
> login(request, users)
> return redirect('welcome.html')
> else:
> return redirect('index.html')
>
>
>
> def logout(request):
> auth.logout(request)
> return render(request, 'login.html')
>
>
>
>
> *Thanks & Regards*
> Ajeet Kumar Gupt
> +91-9311232332
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CA%2BTqRsvD7P8Mk4RCUUg-5%3DYTE7PjBnHyJA%3DVZowGgGoYQnyNKw%40mail.gmail.com
> 
> .
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 

Re: dlango MultiValueDictKeyError

2019-08-05 Thread Sipum Mishra
Hey Ajit,

This error comes when You are trying to get username, passwords from the
form.
It is due to the below reason -

In Login,
You are using -> request.POST['username'] which will raise a KeyError
exception if 'username' is not in request.POST.

Instead use -> request.POST.get('username') which will return None if '
username' is not in request.POST.

Additionally, .get allows you to provide an additional parameter of a
default value which is returned if the key is not in the dictionary.

For example, request.POST.get('username', 'mydefaultvalue')

Hope this helps. If any concern then let us know.

On Mon, 5 Aug 2019 at 15:47, Ajeet Kumar Gupt 
wrote:

> Dear Team,
>
> I am developing custom registration and login page for end-user but
> getting the below error. Please find the views.py code also in the trail.
>
>
> *MultiValueDictKeyError at /login/*
>
> 'username'
>
> Request Method: GET
> Request URL: http://127.0.0.1:8000/login/
> Django Version: 2.2.3
> Exception Type: MultiValueDictKeyError
> Exception Value:
>
> 'username'
>
> Exception Location: 
> C:\Python\Python37\lib\site-packages\django\utils\datastructures.py
> in __getitem__, line 80
> Python Executable: C:\Python\Python37\python.exe
> Python Version: 3.7.3
>
> --
> *Views.py*
> **
>
> rom django.shortcuts import render
> from django.contrib.auth.models import User
> from django.http import HttpResponseRedirect
> from .forms import RegisterForm
> from django.conf import settings
> from django.shortcuts import redirect
> from django.contrib.auth.decorators import login_required
> from django.contrib import messages
> from django.contrib.auth import authenticate,login
> from django.contrib import auth
> from django.core.exceptions import ObjectDoesNotExist
>
>
> def user_register(request):
> # if this is a POST request we need to process the form data
> template = 'mymodule/register.html'
># template = 'index.html'
> if request.method == 'POST':
> # create a form instance and populate it with data from the request:
> form = RegisterForm(request.POST)
> # check whether it's valid:
> if form.is_valid():
> if 
> User.objects.filter(username=form.cleaned_data['username']).exists():
> return render(request, template, {
> 'form': form,
> 'error_message': 'Username already exists.'
> })
> elif 
> User.objects.filter(email=form.cleaned_data['email']).exists():
> return render(request, template, {
> 'form': form,
> 'error_message': 'Email already exists.'
> })
> elif form.cleaned_data['password'] != 
> form.cleaned_data['password_repeat']:
> return render(request, template, {
> 'form': form,
> 'error_message': 'Passwords do not match.'
> })
> else:
> # Create the user:
> user = User.objects.create_user(
> form.cleaned_data['username'],
> form.cleaned_data['email'],
> form.cleaned_data['password']
> )
> user.first_name = form.cleaned_data['first_name']
> user.last_name = form.cleaned_data['last_name']
> user.phone_number = form.cleaned_data['phone_number']
> user.save()
> return redirect('index.html')
> # Login the user
> #login(request, user)
> #def user_login(request):
> # redirect to accounts page:
> #return render(request, '/login.html')
># return HttpResponseRedirect(return, '/login.html')
># No post data availabe, let's just show the page.
> else:
> form = RegisterForm()
> return render(request, template, {'form': form})
>
>
>
>
>
> def login_view(request):
> username = request.POST['username']
> password = request.POST['pass']
> users = authenticate(request, username=username, password=password)
> if users is not None:
> login(request, users)
> return redirect('welcome.html')
> else:
> return redirect('index.html')
>
>
>
> def logout(request):
> auth.logout(request)
> return render(request, 'login.html')
>
>
>
>
> *Thanks & Regards*
> Ajeet Kumar Gupt
> +91-9311232332
>
> --
> 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 django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CA%2BTqRsvD7P8Mk4RCUUg-5%3DYTE7PjBnHyJA%3DVZowGgGoYQnyNKw%40mail.gmail.com
> 

dlango MultiValueDictKeyError

2019-08-05 Thread Ajeet Kumar Gupt
Dear Team,

I am developing custom registration and login page for end-user but getting
the below error. Please find the views.py code also in the trail.


*MultiValueDictKeyError at /login/*

'username'

Request Method: GET
Request URL: http://127.0.0.1:8000/login/
Django Version: 2.2.3
Exception Type: MultiValueDictKeyError
Exception Value:

'username'

Exception Location:
C:\Python\Python37\lib\site-packages\django\utils\datastructures.py
in __getitem__, line 80
Python Executable: C:\Python\Python37\python.exe
Python Version: 3.7.3

-- 
*Views.py*
**

rom django.shortcuts import render
from django.contrib.auth.models import User
from django.http import HttpResponseRedirect
from .forms import RegisterForm
from django.conf import settings
from django.shortcuts import redirect
from django.contrib.auth.decorators import login_required
from django.contrib import messages
from django.contrib.auth import authenticate,login
from django.contrib import auth
from django.core.exceptions import ObjectDoesNotExist


def user_register(request):
# if this is a POST request we need to process the form data
template = 'mymodule/register.html'
   # template = 'index.html'
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = RegisterForm(request.POST)
# check whether it's valid:
if form.is_valid():
if 
User.objects.filter(username=form.cleaned_data['username']).exists():
return render(request, template, {
'form': form,
'error_message': 'Username already exists.'
})
elif User.objects.filter(email=form.cleaned_data['email']).exists():
return render(request, template, {
'form': form,
'error_message': 'Email already exists.'
})
elif form.cleaned_data['password'] !=
form.cleaned_data['password_repeat']:
return render(request, template, {
'form': form,
'error_message': 'Passwords do not match.'
})
else:
# Create the user:
user = User.objects.create_user(
form.cleaned_data['username'],
form.cleaned_data['email'],
form.cleaned_data['password']
)
user.first_name = form.cleaned_data['first_name']
user.last_name = form.cleaned_data['last_name']
user.phone_number = form.cleaned_data['phone_number']
user.save()
return redirect('index.html')
# Login the user
#login(request, user)
#def user_login(request):
# redirect to accounts page:
#return render(request, '/login.html')
   # return HttpResponseRedirect(return, '/login.html')
   # No post data availabe, let's just show the page.
else:
form = RegisterForm()
return render(request, template, {'form': form})





def login_view(request):
username = request.POST['username']
password = request.POST['pass']
users = authenticate(request, username=username, password=password)
if users is not None:
login(request, users)
return redirect('welcome.html')
else:
return redirect('index.html')



def logout(request):
auth.logout(request)
return render(request, 'login.html')




*Thanks & Regards*
Ajeet Kumar Gupt
+91-9311232332

-- 
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 django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BTqRsvD7P8Mk4RCUUg-5%3DYTE7PjBnHyJA%3DVZowGgGoYQnyNKw%40mail.gmail.com.