-1

stuck right now. Trying to make a website and have an ImportError I have no idea how to get around.

Files are organised as such Main folder: website

Secondary folder1: static

Secondary folder2: templates - init.py , auth.py , views.py , models.py

main.py located in main folder

Trying to import from init.py to main.py

init.py

from flask import Flask

def create_app():
    app = Flask(__name__)
    app.config["SECRET_KEY"] = "NG2022"

    return app

main.py

from website import create_app

app = create_app()

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

ImportError: cannot import name 'create_app' from 'website' (unknown location)

Please help, I'm very confused :(

  • do you have a `__init__.py` file in every folder? And if you can show the folder structure with the `tree` command that would be nice – Roy Aug 31 '22 at 15:35

1 Answers1

2

You have to follow the guidelines of file names while separating your project in

> simply rename your init file __init__

further more : when you're importing between your files in the project use the indexing method like

from website.__init__ import create_app

however you don't need to do that for the

>  __init__

file because it execute first automatically

Kilvny
  • 43
  • 7