Cannot import name

Import error:

ImportError: cannot import name 'User'

Can you tell me how to fix it?

Main.py

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///tmp.db'
db = SQLAlchemy(app)

from app.models import *

db.create_all()

from app.algo import funct

Algo.py

from app.main import db
from app.models import User

def funct(): #declaration

Models.py

from app.main import db

class User(db.Model): #declaration

1 answers

"The app folder contains main.py, models.py, algo.py"

If so, then the import should be written like this: from .models import User - remove app, leave the first point (current, relative directory)

 1
Author: microcoder, 2018-07-26 18:15:28