How to create a Hello World WSGI App

22 de agosto, 2016 @ 12:24 — 0 comentarios

You can create an application that simply print the "Hello World " line through a few lines of code. To do this follow these steps:

1 - Define the application from the Hosting Panel

Defines an application called myapp from the Python Applications section of your Hosting Panel.



2 - Setup WSGI file

In the root of yout Python App, create a file called if your aplication is called myapp then you should place it on:


With the following content:

import sys
def application(environ, start_response):
    output = 'Hello World on!\n\nVersion Python: %s' % sys.version

    if sys.version_info.major >= 3:
        output =  bytes(output, encoding="UTF-8")

    status = '200 OK'
    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', len(output))]
    start_response(status, response_headers)

    return [output]

3 - Access the web

That done, if you've chosen for example python 3.5 to run your application, then you will see a message like the following when accessing your website :

Hello World on!

Python 3.5.2 (default, Jun 29 2016, 15:59:39) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]