On Friday 05 May 2017 10:03:47 sum abiut wrote:
> i have try to login user using the guide from
> https://docs.djangoproject.com/en/1.11/topics/auth/default/
>
> but get an error. Can someone advise what i am doin wrong here
It's a flaw in the docs.
It assumes that by now you are familiar with function-based views and how to write them for forms processing.
The code below splits the GET part (rendering the form) and the POST part (processing the form) and you're only shown the POST part. It assumes you already have another view function that renders the form or that the login form is part of many other pages.
> he is my view.py
>
> #Authentication user
> def login(request):
> username=request.POST['username']
> password=request.POST['password']
> user=authenticate(request,username=username,password=password)
> if user is not None:
> login(request,user)
> #Redirect to dashboard page
> return render(request,'dashboard.html')
> else:
> # return invalid login message
> return HttpResponse( 'You have enter a wrong password or
> username please again')
--
Melvyn Sopacua
No comments:
Post a Comment