PyCharm
 
Get PyCharm

Creating a Flask Project

Last modified: 17 June 2024

Flask project in intended for productive development of the Flask applications. PyCharm takes care of creating the specific directory structure, and settings.

PyCharm creates an application and produces specific directory structure, which you can explore in the Project tool window. Besides that, PyCharm creates a stub Python script with the name app.py, which provides a simple "Hello, World!" example.

You can run the created application by pressing ShiftF10 Preview the run results.

Run Flask app

Note that the application was run with the following Flask specific variables:

  • FLASK_APP=app.py – Defines an entry point of the Flask application - the target instance of the Flask class. When extending your Flask application and adding more modules and files, you might need to pass some non-default FLASK_APP values. You can pass a module name, a path to the target Python file, or any combination of modules, scripts, and Flask class instances, for example, FLASK_APP=access_management.access:app2, where:

    • access_management – the module name

    • access – the target file in the module

    • app2 – the Flask class instance in access.

    For more information about the FLASK_APP variable, refer to Flask CLI documentation.

  • FLASK_ENV=development – Sets one of possible environments.

  • FLASK_DEBUG=0 – Controls the built-in Flask debug mode. With this mode enabled FLASK_DEBUG=1, the development server will be automatically reloaded on any code change enabling continuous debugging. For more information about Flask debugger, refer to Flask Debug Mode.

You can change Flask specific variables by editing the corresponding parameters of the Flask Server Run/Debug configuration.

When you've enabled Flask support in your project, the Python console starts acting as a Flask console. Use code completion to enter and execute Flask-specific commands.

Flask console