Last active
September 12, 2024 08:37
-
-
Save drgarcia1986/3cce1d134c3c3eeb01bd to your computer and use it in GitHub Desktop.
Python HelloWorld (WebFrameworks) Collection
This file contains 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 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 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 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 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 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
Thank you bro 😄