jeudi 20 août 2015

Django Sign-in page. Passing arguments in Formname.objects.get(email=email, password=password))

I am creating a sign in page using Django. I want to know whether if i can directly use the variables "email and password" and pass them in query, to check dynamically, whether if email id and password exists in data base, and if it does, then Dashboard.html site should open directly....

try:
    u = RegisterForm.objects.get(email="ram@gmail.com", password=12345678)

Although when i hard code the email id and password(This exists in database) it runs successfully. (as shown ABOVE).

def mainpage(request):
   if request.method == 'POST':
        email = request.POST.get("email")
        password = request.POST.get("password")

        try:
            u = RegisterForm.objects.get(email=email, password=password)
            return render(request, 'Dashboard.html')

        except Exception:
            return render(request, 'Homepage.html')

Am i doing it the wrong way. Pls suggest me right way if i am doing it wrong. But before suggesting me right way pls help me solve above query.

When i input MY EMAIL and MY PASSWORD, i want it to get stored in Email, Password variable. And i want to use it in query to check whether if the Email And Password that i gave exists in my database or not.

And the variable name is same as the column name in the table....!

Aucun commentaire:

Enregistrer un commentaire