Search code examples
pythonflask

flask variable import error give me module not found error


├── app
│   ├── resource |-- user.py
│   ├── app.py

above is my file structure of flask project.

user.py file has

users = Blueprint('user', __name__, url_prefix='/api/v1/user')

app.py file I am importing users variable this way =

from resource.user import users

I want to use users value in app.py but I got this error in server

ModuleNotFoundError: No module named 'resource.user'; 
'resource' is not a package

This is also not workring from app.resource.user import users


Solution

  • You have to create file __init__.py in folder resource.

    That's all.