0

I have used mod_wsgi to create a web server that can be called locally. Now I just found out I need to change it so it runs through the Apache server. I'm hoping to do this without rewriting my whole script.

from wsgiref.simple_server import make_server



class FileUploadApp(object):
    firstcult = ""

    def __init__(self, root):
        self.root = root

    def __call__(self, environ, start_response):

        if environ['REQUEST_METHOD'] == 'POST':
            post = cgi.FieldStorage(
                fp=environ['wsgi.input'],

                environ=environ,
                keep_blank_values=True
            )

        body = u"""
            <html><body>

            <head><title>title</title></head>
            <h3>text</h3>
            <form enctype="multipart/form-data" action="http://localhost:8088" method="post">
            </body></html>
            """


        return self.__bodyreturn(environ, start_response,body)

    def __bodyreturn(self, environ, start_response,body):
        start_response(
                    '200 OK',
                    [
                        ('Content-type', 'text/html; charset=utf8'),
                        ('Content-Length', str(len(body))),
                    ]
                )        
        return [body.encode('utf8')]

def main():
    PORT = 8080
    print "port:", PORT
    ROOT = "/home/user/"
    httpd = make_server('', PORT, FileUploadApp(ROOT))
    print "Serving HTTP on port %s..."%(PORT)
    httpd.serve_forever() # Respond to requests until process is killed

if __name__ == "__main__":
    main()

I am hoping to find a way to make it possible to avoid making the server and making it possible to run multiple instances of my script.

1 Answer 1

2

The documentation at:

explains what mod_wsgi is expecting to be given.

If you also read:

you will learn about the various ways that WSGI application entry points can be constructed.

From that you should identify that FileUploadApp fits one of the described ways of defining a WSGI application and thus you only need satisfy the requirement that mod_wsgi has of the WSGI application object being accessible as 'application'.

Sign up to request clarification or add additional context in comments.

Comments

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.