hello guys, i am trying to make a html form which runs a python script when submitted. I do not know where i am making a mistake and have been stuck for 3 days now! Please help.
I am using XAMPP server on my own computer.
The python code looks like this:
This is driving me nuts! The debugger is not throwing any error. Where am i going wrong..?
PS: the browser just displays this code when the form is submitted.
I am using XAMPP server on my own computer.
The python code looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
#!C:\Users\X\AppData\Local\Programs\Python\Python38-32\python.exe import cgi, cgitb, datetime cgitb.enable() form = cgi.FieldStorage() def get_details(key): if form.getvalue(key): return form.getvalue(key) else : print ( 'returrning NA' ) return 'NA' def base__builder(number): return get_details( 'element' + str (number)) # return 'working' def get_age(a,b, c): dob = datetime.date(day = a, month = b, year = c) age = (datetime.datetime.now().date() - dob) if age < datetime.timedelta(days = 365 ): age = str (age / 30 ) + ' months' else : age = str (age / 365 ) + ' years' return age def get_choice(a, b): for i in a: if base__builder(i) = = 1 : return b[i] else : continue # 1 1 Name name = base__builder( 1 ) # 2 2 CR number crNum = base__builder( 2 ) # 3,4,5 DOB 3-1 Date, 3-2 Month, 3-3 Year age = get_age( int (base__builder( '3_1' )), int (base__builder( '3_2' )), int (base__builder( '3_3' ))) # age = get_age(1,2,2020) # 6 4 Residence residence = base__builder( 6 ) # 7 5 Informant informant = base__builder( 7 ) # 8,9,10 6-1 Male, 6-2 Female, 6-3 Other sex = get_choice([ '6_1' , '6_2' , '6_3' ], [ 'boy' , 'girl' , 'child with ambiguous gender' ]) # 11, 12 7-1 Reliable, 7-2 Unreliable reliability = get_choice([ '7_1' , '7_2' ], [ 'reliable' , 'unreliable' ]) print ( "Content-type: text/html" ) print ("") print ( "<html><head>" ) print ("") print ( "</head><body>" ) print ( '%s is a {1} old {2}, a resident of {3}. The informant is the {4} and the history is {5}' . format (name, age, sex, residence, informant, reliability)) print ( "</body></html>" ) |
PS: the browser just displays this code when the form is submitted.