1

I am running python script on my local server(Apache Server via XAMPP) using Python. Initially, the script was displaying as it was on the text editor. The code I was using was-

#!C:\Users\Gaurav Rai\AppData\Local\Programs\Python\Python37-32\python.exe

def htmlTop():
    print("""
           Content-Type: text/html
          <!Doctype html>
          <html lang=en>
                 <head>
                        <meta charset="UTF-8">
                        <title>My First Server Page in Python</title>
                        </head>
                        <body>
            """)

def htmlTail():
    print("""
          </body>
          </html>
          """)

if  __name__== "__main__" :
    try:
        htmlTop()
        print("""<h1>Hello  World!</h1>""")
        htmlTail()
    except:
        cgi.print_exception()

The output coming was - enter image description here

after taking help from- Running Python scripts with Xampp

I changed my code to-

def htmlTop():
    print("""Content-Type: text/html""")
    print("""
          <!Doctype html>
          <html lang=en>
                 <head>....(remaining code is same) 

After doing this change the code was working fine and the required output "Hello World!" was obtained on the local server.

Can anyone explain what is actually happening here?

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.