How to hide “cgi-bin”, “.py”, etc from my URLs?

后端 未结 6 1967
没有蜡笔的小新
没有蜡笔的小新 2021-02-01 08:49

Brand new to web design, using python. Got Apache up and running, test python script working in cgi-bin directory. Get valid results when I type in the URL explicitly: \".../

6条回答
  •  北海茫月
    2021-02-01 09:38

    The python way of writing web applications is not cgi-bin. It is by using WSGI.

    WSGI is a standard interface between web servers and Python web applications or frameworks. The PEP 0333 defines it.

    There are no disadvantages in using it instead of CGI. And you'll gain a lot. Beautiful URLs is just one of the neat things you can do easily.

    Also, writing a WSGI application means you can deploy on any web server that supports the WSGI interface. Apache does so by using mod_wsgi.

    You can configure it in apache like that:

    WSGIScriptAlias /myapp /usr/local/www/wsgi-scripts/myapp.py
    

    Then all requests on http://myserver.domain/myapp will go to myapp.py's application callable, including http://myserver.domain/myapp/something/here.

    example myapp.py:

    def application(environ, start_response):
        start_response('200 OK', [('Content-type', 'text/plain')])
        return ['Hello World!']
    

提交回复
热议问题