0

I'm using this way to set it

app = Flask(__name__)
app.config['APPLICATION_ROOT'] = "/api"

@app.route("/posts")
def posts():
    ...
    return response, 200

I want to get the endpoint as:

http://localhost:5000/api/posts

But can't show correctly. Got 404 Not Found error.

If use @app.route("/api/posts"), it works.

APPLICATION_ROOT is a builtin feature, why it doesn't work?

Miantian
  • 945
  • 1
  • 11
  • 35
  • 1
    That's not what APPLICATION_ROOT does. See: https://stackoverflow.com/questions/18967441/add-a-prefix-to-all-flask-routes – rdas May 25 '21 at 05:49

1 Answers1

1

You have to set the SCRIPT_NAME env var with your prefix.

Please note, this is a WSGI server feature, and thus the Flask development server ignores it.

Read more at https://dlukes.github.io/flask-wsgi-url-prefix.html

Jürgen Gmach
  • 5,366
  • 3
  • 20
  • 37