Skip to content

Instantly share code, notes, and snippets.

@drgarcia1986
Last active September 12, 2024 08:37
Show Gist options
  • Save drgarcia1986/3cce1d134c3c3eeb01bd to your computer and use it in GitHub Desktop.
Save drgarcia1986/3cce1d134c3c3eeb01bd to your computer and use it in GitHub Desktop.
Python HelloWorld (WebFrameworks) Collection
# -*- coding: utf-8 -*-
from bottle import route, run
@route('/')
def index():
return '<h1>Hello World/h1>'
run(host='localhost', port=8000)
# -*- coding: utf-8 -*-
# Settings
from django.conf import settings
settings.configure(
DEBUG=True,
SECRET_KEY='secretfoobar',
ROOT_URLCONF=__name__,
MIDDLEWARE_CLASSES=(
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
)
# Views
from django.http import HttpResponse
from django.conf.urls import url
def index(request):
return HttpResponse('<h1>Hello Word</h1>')
# Routes
urlpatterns = (
url(r'^$', index),
)
# RunServer
if __name__ == '__main__':
from django.core.management import execute_from_command_line
import sys
execute_from_command_line(sys.argv)
# -*- coding: utf-8 -*-
import falcon
class Index():
def on_get(self, req, resp):
resp.status = falcon.HTTP_200
resp.body = '{"msg": "Hello World"}'
app = falcon.API()
app.add_route(r'/', Index())
if __name__ == '__main__':
from wsgiref import simple_server
httpd = simple_server.make_server('127.0.0.1', 8000, app)
httpd.serve_forever()
# -*- coding: utf-8 -*-
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return '<h1>Hello World</h1>'
app.run()
# -*- coding: utf-8 -*-
import muffin
app = muffin.Application('hello')
@app.register('/')
def products(request):
return {'hello': 'world'}
# -*- coding: utf-8 -*-
import tornado.web
import tornado.httpserver
import tornado.ioloop
class IndexHandler(tornado.web.RequestHandler):
def get(self):
self.finish('<h1>Hello World</h1>')
if __name__ == '__main__':
app = tornado.web.Application([(r'/', IndexHandler)])
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(8000)
try:
print('Server Start')
tornado.ioloop.IOLoop.instance().start()
except KeyboardInterrupt:
print('Server Stop')
@agalera
Copy link

agalera commented Jan 18, 2015

best examples :)

@drgarcia1986
Copy link
Author

Thank you bro 😄

@webmaven
Copy link

Needs a Morepath example. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment