How to use shared hosting Python servers?

My hosting company told me that Python is installed on its servers. How can I use it to display a simple HTML page? At the moment this is like a training exercise, but one day I would like to use Python in the same way as I am currently using PHP.

+3
source share
4 answers

If your server is running an Apache HTTP server, you will need something like mod_wsgi or mod_python installed and running as a module (your server signature can tell you that).

After starting up, you may need to add a handler to the apache configuration or set it by default.

After that, review the middleware documentation for the module you are working in, and then maybe continue and use something like Django.

+2
source

When I used shared hosting, I found that if I renamed the file to .py and prefixed it with the shebang line, it would execute like Python.

#!/usr/bin/python

It was probably a pretty bad practice, but it really worked. Do not expect that you will be able to embroider any extensive web applications from it.

+3
source

: , WSGI, - , HTML ( , , , Mako.

WSGI :

class HelloWorldHandler(object):

    def __call__(self, environ, start_response):
        """
        Processes a request for a webpage
        """
        start_response('200 OK', [('Content-Type', 'text/html')])
        return "<p>Hello world!</p>"

, , : , .

, ​​ paste turbogears, , .

+2
source

You cannot use it "just like" PHP. There are, however, several ways to do this, like Python.

Look at the likes of Turbogears or Django. Either the BFG of you wants something minimalistic, or the WSGI (via mod_wsgi) if you want to go directly to the basics.

http://www.djangoproject.com/

http://bfg.repoze.org/

http://turbogears.org/

http://www.wsgi.org/wsgi/

+1
source

Source: https://habr.com/ru/post/1713842/


All Articles