Python: How to create simple web pages without a huge structure?

I would like to know if there is a way to create web pages without a huge structure in python.

I am thinking of something like PHP / Apache that comes as a language, not a lot of overhead (but I don't like PHP ...). There is no ORM in PHP, no template engine, etc. But it’s very simple to simply print Hello World in a browser.

I know about Django and really love it, but it is too big for simple web portals (5-10 pages).

I really like something simple without installing too much.

+7
source share
8 answers

Have you been looking for Flask ?

This is a much more minimalistic structure, and it is very easy to set up and start.

+4
source

I have used Flask (and bottle.py) in the past, but currently I prefer the Pyramid, from the Pylons people .

Pyramid can be a large, full-fledged structure designed for flexibility and lacks available plugins and extensions, adding additional functionality - but it is also capable of creating small projects with a single file; see this tutorial for an example .

A transition with a pyramid will give you room for growth if your needs expand over time, while maintaining the ability to start a little work.

+4
source

A good old CGI is the fastest way to get started. In most configurations, you just need to remove the python script in 'cgi-bin' and make it executable, no need to install anything. Google for "cgi python", there are many tutorials, for example. this one looks pretty decent.

+2
source

I'm not sure what's wrong with django flatpages for your purposes.

Another alternative would be to replace the django template system with something more powerful, like jinja, so that you can write your own soup soup and process it with minimal logic in the view.

In practice (given that you already know django), this will most likely be simpler than using a microcard (which requires more programmer in exchange for being completely unsupported).

+1
source

mod_python maybe?

0
source

I would recommend CherryPy

 import cherrypy class HelloWorld(object): def index(self): return "Hello World!" index.exposed = True cherrypy.quickstart(HelloWorld()) 
0
source

Of course, you can really rely on the CGI or wsgiref . However, you get what you pay for, and I prefer Flask or WerkZeug for all the pain they prevent.

From wsgiref python docs :

 from wsgiref.simple_server import make_server def hello_world_app(environ, start_response): status = '200 OK' # HTTP Status headers = [('Content-type', 'text/plain')] # HTTP Headers start_response(status, headers) return ["Hello World"] httpd = make_server('', 8000, hello_world_app) print "Serving on port 8000..." # Serve until process is killed httpd.serve_forever() 
0
source

Python works well using CGI.

which is the simplest thing you can do: it only needs apache and the python working environment, and it is closest to the standard php setting.

remember that when using CGI, your python script is responsible for displaying the required HTTP headers ( sys.stdout.write('Content-Type: text/html\n\n') ), but there is a CGI module that is part of the python standard library which helps a lot with raw stuffs (generating post / get arguments, getting headers, generating headers).

0
source

All Articles