Hey,
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
Hey,
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
WSGI is probably what you are looking for. Though there are several lightweight python web frameworks around which are less monolithic than django.
Django is actually quite simple, are you sure you don't want to use it? It can be as simple as you need it to be.
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.
If you don't need Django, try web.py
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()
The truth is that you do need a framework of some sort even if it's extremely minimal. You can use WSGI as a base and at least you're doing a little better. Python is a very powerful, very unspecific programming language so if you decide to do it without a framework you're going to have to rewrite huge amounts of code that you may be taking for granted.
If you do decide to go with something other than Django try this list and maybe you'll find something simple enough that you'll feel good about it. :)
Yep WSGI...
def hello_wsgi(environ, start_response):
start_response('200 OK', [('content-type', 'text/html')])
return ['Hello world!']
If you want to abstract this in terms of request/response to get a little further away from http try webob.
from webob import Request, Response
def hello_wsgi(environ, start_response):
request = Request(environ)
#do something with the request
#return a response
return Response("Hello World!")(environ, start_response)