Search code examples
pythonflaskmoduleruntime-error

the module is not recognized in python (flask)


learning flask and new to web dev here , made the directories as below . in folder named website and in a subfoder named templates make a file init_.py and outside the website folder ,main.py is there

code in init.py

from flask import Flask

def create_app():
    app = Flask(__name__)
    app.config['SECRET_KEY']='madkrish'

    return app

code in main.py


from website import create_app

app = create_app()

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

When i run the main function the following errors comes:

No Module named 'website'

given above

Can someone please correct me where i am wrong i need to go further in the tutorial to the next step.


Solution

  • From your folder structure, you need to import from templates, so:

    from templates import create_app
    

    It should works.

    VSCode will still marks it as error, you need to configure it to inlcude your templates folder in the Python Path