Flask cannot import from website create_app
Question:
ImportError: cannot import name 'create_app' from 'website'
from website import create_app
app = create_app()
if __name__ == '__main__':
app.run(debug=True)
Answers:
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
Make sure you run your __init__.py
file,
Then run the main.py file
Hope it helps:)
ImportError: cannot import name 'create_app' from 'website'
from website import create_app
app = create_app()
if __name__ == '__main__':
app.run(debug=True)
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
Make sure you run your __init__.py
file,
Then run the main.py file
Hope it helps:)