user2872275
user2872275

Reputation:

How to style CGI python with CSS?

Currently I have tried to add a css stylesheet to this CGI python script, the script functions fine and displays h2/links properly but it does not seem to want to use the stylesheet. I added the stylesheet html code before the main() code runs.

def main():
if form.getvalue('option1') == 'option1':
    print "<body>"
    print "<h2> Example </h2>"
    print "<a href=../Form.html> Go back"
    print "</body>"
if form.getvalue('option1') == 'option2':
    print "<body>"
    print "<h2> Example </h2>"
    print "<a href=../Form.html> Go back"
    print "</body>"
if form.getvalue('option1') == 'option3':
    print "<body>"
    print "<h2> Example </h2>"
    print "<a href=../Form.html> Go back"
    print "</body>"

try:
    print "Content-type: text/html\n\n"
    print 
    """
    <link rel="stylesheet" type="text/css" href="../css/StyleSheet.css">
    """
    main()
except:
    cgi.print_exception()

This is my python CGI code above. However it does not seem to be accepting or applying the stylesheet that I want it to. I have tried using a complete url to reference the stylesheet but there is no difference.. Is there any way to add the CSS sheet in some other way?

Thanks.

Upvotes: 1

Views: 2230

Answers (1)

ThisGuy
ThisGuy

Reputation: 2883

Your print statement there just prints a blank line. You need the string to start on the same line as the print statement.

ie:

# this prints a blank line
print
"""
some text
"""

# this prints 'some text'
print """
some text
"""

Also, if you open the page in your browser, you should be able to right-click and do something akin to 'view source', which would show you that this link tag is not there.

Upvotes: 1

Related Questions