Python web application

I want to create a very simple python web application. I do not need Django or any other web design. Isn't there an easier way to create a web application in python?

thanks

+6
python
source share
8 answers

WSGI is probably what you are looking for. Although there are some lightweight python web frameworks that are less monolithic than django.

+3
source share

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() 
+10
source share

Of course! For example

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

this is a web application - if you save it to a file in the corresponding directory of the machine on which the web server is running, and configure the server correctly (depending on the server); The article I pointed out specifically shows how to deploy this web application to the Google App Engine, but almost any web server can serve CGI applications, and this is a simple example.

Of course, CGI has its limits, and you can use more complex approaches (still without a framework!), Such as WSGI (also supported everywhere if nothing else, since it can work on top of CGI, but in most cases you can also deploy it in more advanced ways), and perhaps some of the many great useful components you can deploy using WSGI to keep coding specific parts of your applications.

+5
source share

The truth is that you need some kind of structure, even if it is extremely minimal. You can use WSGI as a base and at least you do a little better. Python is a very powerful, very non-specific programming language, so if you decide to do it without a framework, you will have to rewrite a huge amount of code that you can take for granted.

If you decide to go with something other than Django, try this list and you might find something simple enough to make you feel good. :)

+1
source share

Yep WSGI ...

 def hello_wsgi(environ, start_response): start_response('200 OK', [('content-type', 'text/html')]) return ['Hello world!'] 

If you want to distract this from the point of view of the request / response, in order to get a bit off 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) 
0
source share

I use bottle all the time as minimal web infrastructure. It is very easy to use.

as a minimal example - taken from a website:

 from bottle import route, run @route('/hello/:name') def index(name='World'): return '<b>Hello %s!</b>' % name run(host='localhost', port=8080) 

you just associate a URL (route) with functions. It even gives an optional argument. It has an optional bright template language, and you can customize it for our needs. Very powerful.

It’s also very easy to install - since it comes as a single file next to your application and is clean, compatible with python. It is also very easy to debug, with good startup in modif, while in development mode.

As the final advantages, it runs smoothly under pypy, which provides speed acceleration compared to other platforms.

0
source share

Currently, it is better to use PhusionPassenger Standalone or with NGINX, using the same method as PHP, through a proxy server that passes it FastCGI in the case of PHP and WSGI for Python.

The URL and all explanations for the Passenger can be found: Here

All Python information runs on NGINX on FastCGI , uWSGI or Passenger

About the frameworks that wrap Python to simplify web development. I recommend Django if it is a larger application, and once you hang it up, Django is not so hard.

Good luck

0
source share

You can try Appier ( https://github.com/hivesolutions/appier ). Here is an example application:

 import appier class HelloApp(appier.App): @appier.route("/", "GET") def hello(self): return "Hello World" HelloApp().serve() 

And here is how you run it:

 pip install appier python hello.py 

Disclaimer: This structure is part of my company's open source portfolio. We built a structure to make the code for our consulting work as simple and clean as possible (to increase efficiency). The project is very active, because we use the framework all the time, but the warning is that we just started talking about it publicly recently, so that there is no community around it. However, for this reason, we are very open to working closely with early bird developers to improve our documentation and add new features.

0
source share

All Articles