How do I call one Flask view from another one?

后端 未结 1 826
离开以前
离开以前 2021-02-07 23:32

I have a JSON API in one blueprint module, and a web frontend in another one.

I would like to shave off a few AJAX requests the client JS code would have to make by embe

1条回答
  •  后悔当初
    2021-02-07 23:54

    You can use a Flask test client for this:

    client = app.test_client()
    response = client.get('/your/url', headers=list(request.headers))
    

    To keep the authentication with Flask-Login you need to pass your request's headers.

    Thanks to Chris McKinnel for answering a related question.

    0 讨论(0)
提交回复
热议问题