Flask – Deployment
Externally Visible Server
A Flask application on the development server is accessible only on the computer on which the development environment is set up. This is a default behavior, because in debugging mode, a user can execute arbitrary code on the computer.
If debug is disabled, the development server on local computer can be made available to the users on network by setting the host name as ‘0.0.0.0’.
app.run(host = ’0.0.0.0’)
Thereby, your operating system listens to all public IPs.
A Flask application on the development server is open just on the PC on which the development environment is set up. This is a default conduct, in light of the fact that in debugging mode, a client can execute discretionary code on the computer.
If debug is impaired, the development server on neighborhood PC can be made accessible to the network on system by setting the host name as '0.0.0.0'.
app.run(host = '0.0.0.0')
Thereby, your working OS tunes in to all public IPs.
To switch over from an development environment to an undeniable production environment, an application should be sent on a genuine web server. Contingent on what you have, there are various choices accessible to convey a Flask web application.
For little application, you can consider deploying it on any of the accompanying hosted platforms, all of which offer free arrangement for little application.
Flask application can be conveyed on these cloud platforms. What's more, it is conceivable to send Flask application on Google cloud stage. Localtunnel service enables you to share your application on localhost without disturbing DNS and firewall settings.
If you are slanted to utilize a devoted web server instead of previously mentioned shared platforms, following alternatives are there to explore.
mod_wsgi is an Apache module that gives a WSGI consistent interface to hosting Python put together web applications with respect to Apache server.
To introduce an official discharge direct from PyPi, you can run −
pip introduce mod_wsgi
To check that the installation was successful, run the mod_wsgi-express content with the begin server direction −
mod_wsgi-express begin server
This will start up Apache/mod_wsgi on port 8000. You would then be able to confirm that the installation worked by pointing your program at −
Creating .wsgi file
There should be a yourapplication.wsgi file. This file contains the code mod_wsgi, which executes on startup to get the application object. For most applications, the following file should be sufficient −
from yourapplication import app as application
Make sure that yourapplication and all the libraries that are in use are on the python load path.
You need to tell mod_wsgi, the location of your application.
<VirtualHost *> ServerName example.com WSGIScriptAlias / C:\yourdir\yourapp.wsgi <Directory C:\yourdir> Order deny,allow Allow from all </Directory> </VirtualHost>