Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask project in Visual Studio 2015: how to specify port number?

How can I specify the port number in a Flask python project under Visual Studio 2015, so that when it starts it always uses the same port?

My startup file (app.py) looks like this:

from svc.svc import app
wsgi_app = app.wsgi_app

if __name__ == '__main__':
    import os
    HOST = os.environ.get('SERVER_HOST', 'localhost')
    try:
        PORT = int(os.environ.get('SERVER_PORT', '5555'))
    except ValueError:
        PORT = 5555
    app.run(HOST, PORT)

So I guess that somehow I need to specify the SERVER_PORT environment variable for the debugger process, but I cannot find any option for it.

like image 943
Paolo Tedesco Avatar asked Jun 17 '16 13:06

Paolo Tedesco


People also ask

What is the default port for flask?

The default value is 5000 or it is the port number set in the SERVER_NAME config variable.

How do I open a flask project in Visual Studio?

In Visual Studio, select File > New > Project, search for "Flask", and select the Blank Flask Web Project template. (The template is also found under Python > Web in the left-hand list.)


1 Answers

In Visual Studio, right click on the project name and choose "Properties". Then, click on "Debug" and you will see a "Port Number" and "Environment" section in which you will be able to set the port number and any other environment variables.

Port number and environment variables

like image 127
Avi K. Avatar answered Oct 26 '22 12:10

Avi K.