Hi There
Hi There

Reputation: 187

Flask redirect from a different class

I'm trying to call a function that has a flask redirect which exists in a certain class. My files are like so:

--- Lib/config.py
--- Lib/lib.py
--- auth.py

My code inside lib.py

    import os
    import json
    import time
    import requests
    from Lib.config import APP_UID, REDIRECT_URI
    from flask import redirect


    class PyLi:
        def __init__(self):
            self.app_uid = APP_UID
            self.redirect_uri = REDIRECT_URI

       def code_redirect(self):
        d = {'client_id=' + self.app_uid, 'redirect_uri=' + self.redirect_uri,
            'response_type=' + 'code'}
        return redirect("https://website.com/oauth/authorize?%s" %
            ("&".join(d)))

My config.py is just used to define the env variables I'm calling.

from decouple import config

APP_UID = config('APP_UID', cast=str, default=None)
...

And in auth.py I am calling it like so:

from Lib import lib

@token.route("/authorize", methods=['GET'])
def redirect():
    auth = lib.PyLi()
    auth.code_redirect()

But I'm getting TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.

What am I doing wrong?

Upvotes: 0

Views: 269

Answers (1)

Sam Chats
Sam Chats

Reputation: 2321

You're missing a return on the last line of redirect() view function. Add it as follows:

@token.route("/authorize", methods=['GET'])
def redirect():
    auth = lib.PyLi()
    return auth.code_redirect()

Upvotes: 1

Related Questions