This document discusses running multiple Python web applications under a single WSGI server. It presents a Flask "Hello World" app and a Django "Hello World" app that run on different ports. It then shows how to use a WSGI dispatcher middleware to combine the two apps so they run on the same port from a single command line. Sample code is provided to demonstrate configuring WSGI to dispatch requests between the Flask and Django apps.
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
How do I run multiple python apps in 1 command line under 1 WSGI app?
1. SUSAN TAN
CISCO IN SAN FRANCISCO
TWITTER: @ARCTANSUSAN
HOW DO I RUN MULTIPLE PYTHON APPS
IN 1 COMMAND LINE UNDER 1 WSGI?
2. THIS IS A HELLO WORLD FLASK APP
from flask import Flask, request
app = Flask(__name__)
@app.route('/<name>')
def hello_world(name):
return "Hello %s, I'm a flask app!" % (name)
if __name__ == '__main__':
app.debug = True
app.run()
3. THIS IS A HELLO WORLD DJANGO APP
from django.http import HttpResponse
def hello(request, name):
return HttpResponse("<p>Hello, %s I'm a Django app.</p>" % (name,))
views.py
from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
url(r'^(?P<name>[-w]+)/$', 'hello_django.mysite.myapp.views.hello'),
)
urls.py
4. Django app runs at http://127.0.0.1:8000/
Flask app runs at http://127.0.0.1:5000/
An Observation
HOW DO I COMBINE BOTH PYTHON APPS?
SO THEY’RE BOTH ON SAME PORT? SAME COMMAND LINE ?
7. CONFIGURE WSGI.PY IN DJANGO APP
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE",
"hello_django.mysite.myapp.settings")
# This application object is used by any WSGI server
configured to use this
# file. This includes Django's development server, if
the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
wsgi.py
8. THIS IS A HELLO WORLD COMBINED FLASK & DJANGO APP
from werkzeug.serving import run_simple
from werkzeug.wsgi import DispatcherMiddleware
import hello_flask
from hello_django.mysite.myapp import wsgi as hello_django
application = DispatcherMiddleware(hello_flask.app, {
'/django': hello_django.application
})
if __name__ == '__main__':
run_simple('localhost', 4000, application,
use_reloader=True, use_debugger=True, use_evalex=True)
combined_apps.py
9.
10. Let’s run more python web frameworks in 1
command line
LIVE DEMO TIME