Python Web Beginner: How to redirect to next page

unable to do validation and redirect

Page 1 of 1

0 Replies - 1627 Views - Last Post: 07 May 2009 - 03:18 AM Rate Topic: -----

#1 tks   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 07-May 09

Python Web Beginner: How to redirect to next page

Posted 07 May 2009 - 03:18 AM

Hi I am new to Python. Sadly I have to create a web application urgently. (in Windows OS). Two screens are required as for now:
1) Login
2) Search

Given below is the script that I have written for Login page. It does not throw any error on run but on browsing (the '' in inetmgr), I am unable to redirect/validate the screen.

import cgi
import cgitb; cgitb.enable()

print "Content-type: text/html"
print """
<TITLE>Login Form</TITLE>
<BODY BGCOLOR = white>

	<TD><INPUT type = text name = "user"></TD>
	<TD><INPUT type = password name = "psw">
<INPUT TYPE = hidden NAME = "action" VALUE ="display">
<INPUT TYPE = SUBMIT NAME = "login" VALUE = "Login" onsubmit = validate() >


def validate():
	form = cgi.FieldStorage()
	txt_usr = form.getfirst("user")
	txt_psw = form.getfirst("psw")
	b_login = form.getfirst ("login")
	if(txt_usr !="" and txt_psw !=""):
			db = MySQLdb.connect(host='<host_ip>', user='<username>' , passwd='<pasword>', db='<db_name>')
			curs = db.cursor()
			curs.execute("SELECT query.. = %s;", txt_usr)
			pswrd = curs.fetchone()
			for pwd in pswrd:
				if pwd == txt_psw:
					print "Content-type: text/html"
					print """
								Second page
					print "invalid password"
			print "Username incorrect! Enter valid username"					
		 print "Enter username and password"

I know that we can redirect to next page by including following in the login HTML :


but this again goes to next page without validation..
I checked out few sites, which talks about 'Sessions' and 'Cookies'. It looks greek and latin to me.

It would be great if anyone can tell me

1) the changes that are required in this script
2) In Python how can i validate a page on Submit button instead of <Form> (any onsubmit property?)
3) Do I require to use Sessions and cookies.


Is This A Good Question/Topic? 0
  • +

Page 1 of 1