2

I want to know that if I can make a web server with Flask in my pc like xampp apache (php) for after I can access this page in others places across the internet. Or even in my local network trough the wifi connection or lan ethernet. Is it possible ? I saw some ways to do this, like using "uwsgi".. something like this... but I colud never do it.

OBS: I have a complete application in Flask already complete, with databases and all things working. The only problem is that I don't know how to start the server and access by the others pc's.

2 Answers2

2

Yes, you can.

Just like you said, you can use uwsgi to run your site efficiently. There are other web servers like uwsgi: I usually use Gunicorn. But note that Flask can run without any of these, it will simply be less efficient (but if it is just for you then it should not be a problem).

You can find tutorials on the net with a few keywords like "serving flask app".

If you want to access your site from the internet (outside of your local network), you will need to configure your firewall and router/modem to accept connections on port 80 (HTTP) or 443 (HTTPS).

Good luck :)

pawamoy
  • 3,382
  • 1
  • 26
  • 44
2

Yes, you can do this with the flask built-in web server, but you should probably use a proper web server like apache or nginx along with a wsgi application in front of your flask service. The Flask Docs have an entire section on deploying your site with a web service

But if you really want to just use the testing web server that comes with flask, the Flask Docs explain how to expose your flask app externally:

If you run the server you will notice that the server is only accessible from your own computer, not from any other in the network. This is the default because in debugging mode a user of the application can execute arbitrary Python code on your computer.

If you have the debugger disabled or trust the users on your network, you can make the server publicly available simply by adding --host=0.0.0.0 to the command line:

flask run --host=0.0.0.0

This tells your operating system to listen on all public IPs.

If you want to serve that up to other PC's outside your local network, you'll have to configure port forwarding on your router, to forward port 80 or port 443 requests from outside your network to the specific PC running a flask webserver on your local network.

Be aware that some ISP's block port 80 requests to prevent you from serving a website from your home.

Community
  • 1
  • 1
Brendan Abel
  • 35,343
  • 14
  • 88
  • 118
  • Hi i seen this tip in flask site... but I don't got it perfectly this command.. beacuse I'm using Flask_script manager and I don't know how to get together the flask run ( flask run --host=0.0.0.0 )and the ("app.py runserver") in the code... can you give me a tip ? – Sóstenes Apollo Apr 04 '18 at 17:35
  • If `Flask-Script` is what you're using, it looks like you can pass arguments to flask [this way](https://flask-script.readthedocs.io/en/latest/#default-commands) – Brendan Abel Apr 04 '18 at 17:44
  • manager = Manager(app) manager.add_command("runserver", Server(host="192.168.1.11", port=8000)) – Sóstenes Apollo Apr 04 '18 at 17:56