I separated my flask errorhandlers into a separate module called 'error_handlers.py' within my 'app.py' directory. I have tried importing the error_handlers module into the app module but i keep getting an ImportError:
from app import app ImportError: cannot import name 'app' from partially initialized module 'app' (most likely due to a circular import)
I looked up a similar question and added blueprint but i'm still getting the same error. Please is there anything I'm doing wrong. My code below:
app.py
import os
from error_handler import *
from flask import Flask, flash, jsonify, redirect, render_template, request, session, abort
from flask_session import Session
from tempfile import mkdtemp
from helpers import lookup, login_required
# Configure application
app = Flask(__name__)
app.register_blueprint(error_handlers.blueprint)
...
error_handlers.py
from app import app
from flask import render_template, Blueprint
blueprint = Blueprint('error_handlers', __name__)
@blueprint.app_errorhandler(404)
def page_not_found(e):
return render_template("errors/404.html")
Aucun commentaire:
Enregistrer un commentaire