[Flask] urls when running under gunicorn

S McGraw smcg4191 at mtneva.com
Thu Oct 15 01:46:29 CEST 2015


I tried setting app.config['APPLICATION_ROOT'] (and verified it was set
by running in a debugger) but it seemed to have no effect on the urls 
produced by url_for(), with or without the FixProxy middleware.
The docs for url_for() say nothing about how they generate urls, and the 
"config" docs can be interpreted as saying APPLICATION_ROOT is only used 
when dealing with cookies.  I glanced at the code for url_for() but it
was way beyond me.

So I am still rather at a loss...  Have you (or anyone) actually used 
APPLICATION_ROOT to affect what url_for() produces?  An affirmative 
answer will tell me I screwed up something here when trying to use it.)

Thanks.

On 10/13/2015 01:00 PM, Corey Boyle wrote:
> I think what you are looking for is the "APPLICATION_ROOT" config item.
> http://flask.pocoo.org/docs/0.10/config/
> 
> But don't take my word for it.
> 
> On Tue, Oct 13, 2015 at 1:26 PM, S McGraw <smcg4191 at mtneva.com> wrote:
>> I new to flask and have a small first app working under flask's
>> development server.  In the templates I used url_for(), under the
>> impression that would adjust the app's urls when I later run it
>> behind a web server.
>>
>> I have now gotten it to run under gunicorn and set up a reverse
>> proxy to it in my Apache (2.4) web server.  It worked ok when
>> configured as a virtual host.  However, I want to run my app under
>> a url in my regular url namespace, eg:
>>   http://myhost.com/myapp/(login,main,etc...)
>> The trouble is that the urls in the rendered templates are still
>> "/login", "/main", etc rather than /myapp/login, /myapp/main, etc
>> which of course result in a 404 when clicked on.  So I'm sure there
>> is some step or piece of code I'm missing.
>>
>> FWIW, I tried using the werkzeug ProxyFix middleware suggested in
>> the "Proxy Setups" section of the Flask docs, no effect.  I saw
>> recommendations to use Flask Snippets #35, along with configuring
>> the web server to send certain headers, but they all seemed to be
>> for Nginx, and seemed an awfully heavy-weight answer.  Surely there
>> is a simpler flask-only way to fix this?  Also I read about Apache's
>> mod_proxy_html but that too seems a little overkill to me.)
>>
>> I did get things to work by losing the url_for()'s in my code and
>> templates, replaced with eg, g.prefix+'/main', where g.prefix is set
>> to "/myapp" in a before_request() function. But I don't think that's
>> the recommended practice. ;-)
>>
>> What am I missing?
>> _______________________________________________
>> Flask mailing list
>> Flask at python.org
>> https://mail.python.org/mailman/listinfo/flask


More information about the Flask mailing list