如何解决此循环导入问题?

时间:2020-12-29 02:40:43

标签: flask

我正在尝试使用像 DB_PASSWORD 这样的配置变量,我在 config.py 中定义了它。

from flask import Flask, Blueprint

def create_app():
    app = Flask(__name__)
    app.config.from_object('website.config.Config')

    with app.app_context():

        from .api.clientes.clientes import cliente 
        app.register_blueprint(cliente)
        return app


api/
 |--customers/
 |-------------customer.py
 |-------------controllercustomer.py

好吧,在 ControllerCustomer 内,如果我调用 create_app() 来使用配置,我会收到此错误

<块引用>

ImportError: 无法从部分初始化中导入名称“客户” 模块“website.api.customers.customer”(很可能是由于循环 进口) (/home/thiago/Documentos/Coding/api_project/api/src/website/api/customers/customer.py)

from flask import Blueprint, render_template, jsonify, request, url_for, redirect,current_app
from website.api.customer import controllercustomer

customer = Blueprint('clientes',__name__,url_prefix='/api/customer')

@customer.route('/')
def index():
    return jsonify('Hello World')

我不知道我的方法是否正确,或者还有其他方法可以调用这些变量

0 个答案:

没有答案