-
-
Save synthetic-intelligence/d9b3fe5419fc149dbc5c84d9258589e2 to your computer and use it in GitHub Desktop.
Python HelloWorld (WebFrameworks) Collection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from bottle import route, run | |
@route('/') | |
def index(): | |
return '<h1>Hello World/h1>' | |
run(host='localhost', port=8000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from flask import Flask | |
app = Flask(__name__) | |
@app.route('/') | |
def index(): | |
return '<h1>Hello World</h1>' | |
app.run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import muffin | |
app = muffin.Application('hello') | |
@app.register('/') | |
def products(request): | |
return {'hello': 'world'} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment