Open Artucuno opened 2 years ago
Hello, I had the same problem with quart_discord. All you need to do is move
discord = DiscordOAuth2Session(app)
to your main file, and then import discord from main in your blueprint file. Also to prevent circular imports remember to wrap import of blueprint and app.run() in if statement, something like that
if __name__ == "__main__":
from blueprints.api import api
from blueprints.dashboard import dashboard
app.register_blueprint(api)
app.register_blueprint(dashboard)
app.run(host="localhost", port=5000, debug=True)
For me it works perfectly
Your blueprint should look like that
...
from flask.blueprints import Blueprint
from main import app, discord
dashboard = Blueprint('dashboard', __name__, url_prefix='/dashboard', template_folder="../templates/dashboard/")
...
And your main
app = Flask(__name__)
...
discord = DiscordOAuth2Session(app)
if __name__ == "__main__":
from blueprints.api import api
from blueprints.dashboard import dashboard
app.register_blueprint(api)
app.register_blueprint(dashboard)
app.run(host="localhost", port=5000, debug=True)
Hey, thanks for your reply. I fixed the issue in the end by just using oauthlib and doing it from scratch just because for my case, I can't have discord imported in the main file.
Hi, @Artucuno. I'm Dosu, and I'm helping the Flask-Discord team manage their backlog. I'm marking this issue as stale.
Issue Summary:
AttributeError
when using Flask-Discord within a Flask blueprint.current_app
instead of the blueprint context.DiscordOAuth2Session
initialization to the main file to avoid circular imports.Next Steps:
Thank you for your understanding and contribution!
Hey, I need to use Flask-Discord in a blueprint but I am not sure if that is possible.
I get the error
AttributeError: 'Flask' object has no attribute 'discord'
and I think its because it uses current_app instead of the blueprint itself.Thanks