'Flask cannot import from website create_app

ImportError: cannot import name 'create_app' from 'website'
from website import create_app

app = create_app()

if __name__ == '__main__':
    app.run(debug=True)


Solution 1:[1]

whether you want a file that can be run as the main program or imported by other modules. We can use an

if __name__ == "__main__" block

to allow or prevent parts of code from being run when the modules are imported.

When the Python interpreter reads a file, the name variable is set as main if the module being run, or as the module's name if it is imported. Reading the file executes all top level code, but not functions and classes (since they will only get imported).

Sample code of flask

from flask import Flask

app = Flask(__name__)

@app.route("/")
def home():
    return "Hello, World!"
    
if __name__ == "__main__":
    app.run(debug=True)

I believe your the fault is instead of name == "main", you put name == main

Solution 2:[2]

you should put init.py under website folder, not inside any folder else like static or templates folders

like this

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RCvaram
Solution 2 Almadani