Hi i am getting **ImportError: cannot import name ‘app’ from partially initialized module ‘app’ (most likely due to a circular import) **
my directory :
ICT239
|
app
|
_pycache
|
controllers
|
| – – – _pycache
| – – – tours.py
|
models
|
| – – – _pycache
| – – – toursData.py
|
static
|
| – – – css
| – – – img
| – – – js
|
templates
|
venv
|
init.py
|
app.py
|
requirements.txt
app.py
`from flask import render_template
from app import app
@app.route("/")
@app.route("/about")
def about():
return render_template("about.html")`
**
init.py**
`from flask import Flask
from controllers.tours import toursBP
def create_app():
app = Flask(__name__)
app.config['SE']
app.register_blueprint(toursBP)
return app
app = create_app()`
tours.py:
`from flask import Blueprint,render_template
from models.toursData import Tour
toursBP = Blueprint("toursBP",__name__)
@toursBP.route("/tours")
def tours():
tours,countries = Tour.getAllToursBy()
print(tours)
return render_template("tours.html",tours =tours,countries = countries)`
anyone can help? I haven’t move on to Mongoengine database and I alr had a error. Sry still learning ~
koh chaik hong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
You have a file named app.py
.
This file is causing the error.
Change the name of the file to something else and try again.
Note: Please refrain from naming your files with module names, keywords, etc
from app import app
means from package app import object app
But since you have a file named app.py
it is trying to import from it.
2