Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python web application

Tags:

python

I want to create a very simple python web app. I don't need Django or any other web framwwork like that. Isn't there a simpler way to create a web app in python?

Thanks

like image 379
pns Avatar asked Dec 06 '09 00:12

pns


People also ask

Can Python be used for web applications?

Python is commonly used for developing websites and software, task automation, data analysis, and data visualization. Since it's relatively easy to learn, Python has been adopted by many non-programmers such as accountants and scientists, for a variety of everyday tasks, like organizing finances.

Is Python a Flask?

Flask is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries.


3 Answers

If you don't need Django, try web.py

http://webpy.org/

import web

urls = (
    '/(.*)', 'hello'
)
app = web.application(urls, globals())

class hello:        
    def GET(self, name):
        if not name: 
            name = 'world'
        return 'Hello, ' + name + '!'

if __name__ == "__main__":
    app.run()
like image 163
YOU Avatar answered Oct 05 '22 02:10

YOU


Sure! For example,

print 'Content-Type: text/plain'
print ''
print 'Hello, world!'

this is a web app -- if you save it into a file in an appropriate directory of a machine running a web server and set the server's configuration properly (depending on the server); the article I pointed to specifically shows how to deploy this web app to Google App Engine, but just about any web server can serve CGI apps, and this is a simple example thereof.

Of course, CGI has its limits, and you can use more sophisticated approaches (still short of a framework!) such as WSGI (also universally supported, if nothing else because it can run on top of CGI -- but in most cases you can also deploy it in more advanced ways) and possibly some of the many excellent utility components you can deploy with WSGI to save you work in coding certain parts of your apps.

like image 28
Alex Martelli Avatar answered Oct 05 '22 01:10

Alex Martelli


WSGI is probably what you are looking for. Though there are several lightweight python web frameworks around which are less monolithic than django.

like image 28
tosh Avatar answered Oct 05 '22 02:10

tosh