Hello,
You should check by which method was called your view.
something like
if request.method == "POST":
#now you can use request.POST
else:
#just show the template
Hope that helps,
Matias.
On Mon, Dec 15, 2008 at 5:15 AM, vierda <[email protected]> wrote:
>
> Dear Ronny/all,
>
> Thank you for your reply. I have modified my code and the error still
> occur.
> my new code as following below:
>
> def my_view(request):
> username = request.POST['username']
> password = request.POST['password']
> user = authenticate(username=username, password=password)#create
> Authentication object
> render_to_response ('login.html', {'username': username,
> 'password' : password})
>
> if user is not None:
> if user.is_active:
> login(request,user)
> return render_to_response('success.html',
> {'username':username})
> else:
> return HttpResponse('disabled account')
> else:
> return HttpResponse('invalid login')
>
> and my login.html as per below:
> <form action="/login/" method="POST">
>
> Enter Username: <input type=text name="username">
> Enter Password: <input type=password name="password">
> <input type="submit" Value="Login"/>
> </form>
>
> my success.html as per below :
> <html>
> <h1> welcome{{username}}</h1>
> </html>
>
> somebody kindly help and thank you in advance
>
>
> On Dec 6, 12:05 am, "Ronny Haryanto" <[email protected]> wrote:
> > On Sat, Dec 6, 2008 at 2:42 PM, vierda <[email protected]> wrote:
> > > today I try to make login page with follow example code in
> > > djangoproject (user authentication chapter), code as following below :
> >
> > > def my_view(request):
> > > username = request.POST['username']
> > > password = request.POST['password']
> > > user = authenticate(username=username, password=password)#create
> > > Authentication object
> >
> > > if user is not None:
> > > if user.is_active:
> > > login(request,user)
> > > return HttpResponse('login success')
> > > else:
> > > return HttpResponse('disable account')
> > > else:
> > > return HttpResponse('invalid login')
> >
> > > the above code always shows MultiValueDictKeyError with exception
> > > value "Key 'username' not found in <QueryDict: {}>".
> >
> > That exception will always be raised if the view is called via GET
> > method instead of POST.
> >
> > If you're sending it via POST, then the information you provided was
> > not sufficient. We need to see template code that renders the form (or
> > the html form if you're not using templates) and probably the form as
> > well.
> >
> > Ronny
> >
>
--
:wq
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---