Python Forum
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Back end issues
#1
Im doing a front and back end project which will be run on apache 2.4.7
So far however, my backend, when requested by the front end, returns an error. Pls send help.

FRONT END:
<!DOCTYPE html>
<html>
 <head>
   <title>SAT College Board 2010 School Level Results</title>
 </head>
 
 <body>
SAT SCHOOL LEVEL RESULTS !!! <br>
   <form action = "Backend.py">
What is the name of the school whose results you wish to view?
     <input type = "text" name = "school"> <br>
What is the District Number?
     <input type = "number" name = "dn"> <br>        
     <input type = "submit" name = "doThis" value = "Submit Form">
   </form>
 </body>
</html>

BACK END:
#! /usr/bin/python

print 'content-type: text/html \n'

import cgitb
cgitb.enable()

import cgi
fs = cgi.FieldStorage()
import csv

DB =open('SAT_School_Participation_and_Performance__2012-2013.csv', 'rb')
readerObject = csv.reader( DB)
for record in readerObject:
   account = line.split(",")
   if record.append(account[0]) = data["school"].value
return record
   if record.append(account[1]) = fs["dn"].value
       return record
DB.close()
Reply
#2
It would help if you would post the full text of the error you are getting. My guesses by looking at your code are that you don't define the data variable used in line 16 (did you mean fs instead?) and you can't use return outside of a function.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Why to you have to cgi Sick
As mention it shoul be fs.
Front end:
print('''\
Content-Type: text/html\n
<!DOCTYPE html>
<html>
  <body>
    <form action="Backend.py">
      What is the name of the school whose results you wish to view?<br>
      <input type="text" name="school">
    </form>
  </body>
</html>''')
Use fs.getvalue('school') to get vaule from form.
backend.py:
import cgitb
cgitb.enable()
import cgi
fs = cgi.FieldStorage()

name = fs.getvalue('school')

print( """\
Content-Type: text/html\n
<html>
 <body>
   <h2>The submitted name was "{}"</h2>
 </body>
</html>
""".format(name))
Reply
#4
(Jun-11-2017, 03:05 AM)brianmluo Wrote:
if record.append(account[0]) = data["school"].value return record
if record.append(account[1]) = fs["dn"].value

Is it a syntax error?  Because you need two equal signs == to check equality.  One would be for assignment, which is only legal in statements, not expressions.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020