| 1. |
What is Application Dispatching? Show an example of application dispatching with any WSGI server. |
|
Answer» On the WSGI level, application dispatching is the process of JOINING numerous Flask apps. You can MIX and match any WSGI application, not only Flask. If you like, you can run a Django and a Flask application in the same interpreter at the same time. This is only useful if you know how the programs function within. The main distinction between this and Large Applications as Packages is that you're running the same or different Flask applications that are completely separate from one another. They are dispatched on the WSGI level and run distinct configurations. Each technique and example below produces an application object that may be run on any WSGI server. See Deployment Options for production options. Werkzeug PROVIDES a server for development via werkzeug.serving.run_simple(): from werkzeug.serving IMPORT run_simple[Text Wrapping Break]run_simple('localhost', 5000, application, use_reloader=True)It's worth noting that run simply isn't meant to be used in production. Make USE of a production-ready WSGI server. See Deployment Options for more information. Debugging must be enabled on both the application and the simple server in order to use the interactive debugger. The "hello world" example with debugging and run_simple is as follows: from flask import Flask[Text Wrapping Break]from werkzeug.serving import run_simple[Text Wrapping Break][Text Wrapping Break]app = Flask(__name__)[Text Wrapping Break]app.debug = True[Text Wrapping Break][Text Wrapping Break]@app.route('/')[Text Wrapping Break]def hello_world():[Text Wrapping Break] return 'Hello World!'[Text Wrapping Break][Text Wrapping Break]if __name__ == '__main__':[Text Wrapping Break] run_simple('localhost', 5000, app,[Text Wrapping Break] use_reloader=True, use_debugger=True, use_evalex=True) |
|