Skip to content
Advertisement

PyCharm is giving an unused import error for routes, and models

I am trying to build a basic Flask project. Here is the app.py file.

JavaScript

PyCharm is telling me that route, and models are unused imports. They are located in the same root directory together. I’m not sure how to get these imported another way without having a circular import error.

Advertisement

Answer

An ideal way would be to use this structure where each module is separately handled:

JavaScript

From __init__.py, you will create an instance of your flask app:

JavaScript

Importing routes and models (and any other module you might have) at the bottom of __init__.py helps avoid circular dependencies issue.

The app.py is left as an entry point to your application:

JavaScript

Your configurations will go the config.py file:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement