0

Flask application uses Api for better endpoint group. For example, i have

class Example(Resource):
    parser = reqparse.RequestParser()
    parser.add_argument('email', type=str, required=True, location='form')
    def post(self):
        data = self.parser.parse_args()
        email = data['email']
        # do smth with db
        # returning some dummy info
        return {'msg': f'Hello {email}'}

api.add_resource(TestHelloWorld, '/hello')

@app.route('/extended')
def extended():
    # How do i call resource /hello
    result = Example.post('dummy@email.com')

The question is: in my /extended route - how do i call the /hello resource?

aleksander
  • 23
  • 5
  • Do you want to call the other function or do you want to redirect the browser to the other endpoint? – zvone Apr 28 '23 at 08:54
  • not sure about redirect, but might be a solution also.. – aleksander Apr 28 '23 at 09:00
  • 1
    If you want to redirect, you just need to return the redirect response. If you don't want to redirect, then you should extract the code which is used by both endpoints into a separate function which is not an endpoint, and then call that from both endpoints. – zvone Apr 28 '23 at 14:47
  • how does code snipet looks for redirect? return redirect(url_for('/hello, email=email) ) – aleksander Apr 29 '23 at 08:48

0 Answers0