Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Options for building a python web based application

Tags:

python

web

I am building a simple Python web application and I want it to run stand alone like SABNZBD or Couch Patato. These applications are self contained web applications. What do these products use to serve up the web interface?

The application im building will do a lookup of images albums (folders) and when selected, present it a slide show kind of way. All information is in a XML file, so no database needed. My goal is to make the application as self contained as possible.

I have looked at Django and it looks a bit daunting and overkill for my application, what are my other options.

Thanks Darrell.

like image 691
DeChinees Avatar asked Aug 16 '13 09:08

DeChinees


3 Answers

why don't you use flask in python ?

take a look at this http://flask.pocoo.org/

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()
like image 159
Alireza Sanaee Avatar answered Oct 09 '22 16:10

Alireza Sanaee


There are many options and they're all very easy to pick up in a couple of days. Which one you choose is completely up to you.

Here are a few worth mentioning:

Tornado: a Python web framework and asynchronous networking library, originally developed at FriendFeed.

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

application = tornado.web.Application([
    (r"/", MainHandler),
])

if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()



Bottle: a fast, simple and lightweight WSGI micro web-framework for Python. It is distributed as a single file module and has no dependencies other than the Python Standard Library.

from bottle import route, run, template

@route('/hello/<name>')
def index(name='World'):
    return template('<b>Hello {{name}}</b>!', name=name)

run(host='localhost', port=8080)



CherryPy: A Minimalist Python Web Framework

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

cherrypy.quickstart(HelloWorld())



Flask: Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions.

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()



web.py: is a web framework for Python that is as simple as it is powerful.

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 31
MrD Avatar answered Oct 09 '22 17:10

MrD


You can try something simpler, like Bottle, which is just one python file and gives you most of the web handling without unnecessary sophistication:

from bottle import route, run, template

@route('/hello/<name>')
def index(name='World'):
    return template('<b>Hello {{name}}</b>!', name=name)

run(host='localhost', port=8080)
like image 3
deStrangis Avatar answered Oct 09 '22 18:10

deStrangis