[Flask] flask url_for / nginx proxy_pass

Pascal patatetom at gmail.com
Fri Jun 10 08:16:56 EDT 2016


thank you for track Ulrich

I've changed the url prefixes defined in default.py
<https://github.com/sh4nks/flaskbb/blob/master/flaskbb/configs/default.py#L117-121>
and used in app.py
<https://github.com/sh4nks/flaskbb/blob/master/flaskbb/app.py#L80-89> with
register_blueprint.
I've also changed nginx directive to <code>location /flaskbb/ { proxy_pass
http://127.0.0.1:8765/flaskbb/; }</code>.

now links are good :-) except static files like css :-(.

for example, this link <link rel="stylesheet"
href="/static/css/styles.css"> is made with template layout.html
<https://github.com/sh4nks/flaskbb/blob/master/flaskbb/templates/layout.html#L26>
by url_for...


2016-06-10 12:43 GMT+02:00 Ulrich Berthold <ub at artfacts.net>:

> hey pascal,
>
> when using blueprints, you can pass the url prefix as an argument to
> register_blueprint, like this:
>
> app.register_blueprint(api, url_prefix='/api')
>
> will make api aceesable under https://my.url/api and urls created with
> url_for in that context will have the prefix.
>
> there is a  stackoverflow question, which i think handles your problem:
>
> http://stackoverflow.com/questions/18967441/add-a-prefix-to-all-flask-routes
>
> cheers,
> ub
>
>
> On Fri, Jun 10, 2016 at 11:52:57AM +0200, Pascal wrote:
> > hello,
> >
> > my flask app (flaskbb <https://github.com/sh4nks/flaskbb>) is listening
> on
> > 127.0.0.1:8765 and is ok when accessed directly with
> http://127.0.0.1:8765/.
> >
> > when accessed through nginx with http://mywebserver/flaskbb/, all links
> are
> > broken because /flaskbb is missing in the url (eg. src="/css/..." and not
> > src="/flaskbb/css/...").
> >
> > I currently bypasses the problem by modifying the templates, but it's not
> > clean :-(
> >
> > how can I solve this problem ?
> >
> > note that nginx directive is location /flaskbb/ { proxy_pass
> > http://127.0.0.1:8765/; } and I can't play with virtual-server/dns.
>
> > _______________________________________________
> > Flask mailing list
> > Flask at python.org
> > https://mail.python.org/mailman/listinfo/flask
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20160610/42ce27ba/attachment.html>


More information about the Flask mailing list