2

I followed this guide, but this didn't work. I have a HTML page with form that sends a name and number to this site.

Here's the Python Code:

#!/usr/bin/env python
import cgi, cgitb 
import os
import loadXML
import display
from xml.etree import ElementTree
form = cgi.FieldStorage() # instantiate only once!
#import file
file_name = 'testrecords.xml' 
full_name = os.path.abspath(os.path.join('xml', file_name))
# get variables from html 

htmlName = 'lewis' #form.getfirst('name', 'empty')
htmlNumber = 1 #form.getvalue('searchcrit')


#htmlName = cgi.escape(htmlName)

# initialize variables
search = ['blank','name','activity','year','title']
searchnumber = ['1','2','3','4']

searchXML = loadXML.searchingall(full_name) #finds all xml entries 
(name, activity, record, num, year) =  display.display(searchXML,htmlName,int(htmlNumber),search) 
#all vars coming out of the line above are arrays
x = 0
addedArrays = ["None"]
while name[x] != "Empty":
    addedArrays[x] = (str(name[x])+ "," + str(activity[x]) +","+ str(record[x]) +","+ str(num[x])+","+ str(year[x]))
    x = x + 1
    addedArrays.append(x)



with open('/home/ubuntu/workspace/test.html') as f: 
    htmlFile=(f.read())
print("""\
Content-Type: text/html\n 
"""+ htmlFile % addedArrays)

#print("""\
#Content-Type: text/html\n
#<html>
#<body>
 #<p class="page-description">The returned items were "%s"</p>
#</body>
#</html>
#""" % addedArrays)

Here's the HTML code:

<html>

<body>

    <p class="page-description">The returned items were "%s"</p>
</body>

</html>

Here's the HTML file:

<!DOCTYPE html>
<html>

<head>
    <!--under the black menu line in large text saying CLHS Records-->
    <title>CLHS Records</title>
    <link rel="stylesheet" type="text/css" href="Stylesheet.css">
    <!--This connects your stylesheet.css to html-->
</head>

<body>
    <!--this is the start of your body of the page-->
    <div class="nav">
        <!--This is what keeps seachbar in line with your names-->
        <div class="nav_wrapper">
            <!--This is what holds the search bar in place-->
            <form method="get" action="/cgi-bin/pyHandler.py" />
            <form class="form-wrapper">
                <input type="text" name="name" placeholder="Enter Name">
                <input type="radio" name="searchcrit" value="1">Name
                <input type="radio" name="searchcrit" value="3">Year
                <input type="radio" name="searchcrit" value="2">Activity
                <input type="radio" name="searchcrit" value="4">Records
                <input type="submit" value="Submit" a href="https://schoolrecordproject-jasonchristenson.c9users.io/html/Results.html" />
            </form>
        </div>
        <img class="lionimage" width="12%" src="http://clearlakeschools.org/wp-content/uploads/2016/12/Charging-Lion.png" />
        <!--this is the lion image above the title clhs records-->
        <h1 class="page-title">CLHS Records</h1>
        <p class="page-description"> On this webpage you will be able to view record holders over the various years at Clear Lake High school. You will be able to search the file by name,year,activity, and record. </p>
        <!--discription in middle of page describing-->
        <div class="navigation">
            <nav>
                <ul>
                    <li><a href="#"><b> Clear Lake Athletics </b></a></li>
                    <li><a href="http://clearlakeschools.org/about/"><b> About Clear Lake District </b></a></li>
                </ul>
                <div class="contact-btn">
                    <a href="mailto:">Contact</a>
                </div>
            </nav>
        </div>
</body>

</html>

We just have a basic XML file that this is referencing as well as all the python files like the display file.

Basically my problem is on the Python file, if I uncomment the last 8 lines, everything works great, but I need this to import another HTML file to do what the last eight lines do, but we need it to be able to externally update the html file and change formatting etc.

If I run the last eight lines, it works fine, but if I run this:

with open('/home/ubuntu/workspace/test.html') as f: 
htmlFile=(f.read())
print("""\
Content-Type: text/html\n 
"""+ htmlFile % addedArrays)

then it doesn't work.

What do I need to do to make it work? Thanks!

4
  • What, precisely, does "it doesn't work" mean? What, precisely, does it do? Commented Jan 12, 2017 at 15:42
  • Sorry, I get the 500 server error that says stuff isn't configured properly Commented Jan 12, 2017 at 17:20
  • Does your server provide more information in its log files? Commented Jan 12, 2017 at 17:22
  • Have you tried the testing tricks for your CGI script from the Standard library documentation ? Commented Jan 15, 2017 at 21:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.