D
D
Dmitry Stepanov2019-03-13 11:34:36
Python
Dmitry Stepanov, 2019-03-13 11:34:36

Why does url_for duplicate url_prefix for blueprint when running flask via fcgi?

Good afternoon. There is a simple Flask application:
api.py

from flask import Blueprint
from flask import url_for, jsonify

api = Blueprint('api', __name__)

@api.route('/', methods=['GET', 'OPTIONS'])
def index():
    links = dict()
    links['docs'] = url_for('.docs')
    return jsonify(_links=links)


@api.route('/docs/', methods=['GET'])
def docs():
    doc = {
        " key": "value"
    }
    return jsonify(doc), 200

app.py
from flask import Flask, request
from .api import api

app = Flask(__name__)
app.register_blueprint(api, url_prefix='/api')

If you run the application via app.run()
from .app import app
if __name__ == '__main__':
    app.run(debug=True)

then when I make an /api/ request, I receive a resource with a normal link /api/docs/
in response. If I run the application on the server via WSGI:
from .app import app
from flup.server.fcgi import WSGIServer
if __name__ == '__main__':
    WSGIServer(app, bindAddress='/tmp/fcgi.sock').run()

when I make an /api/ request, I receive a resource with a link /api/api/docs/ in response .
Where does the duplicate come from? With what it can be connected and how to treat?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question