[Flask] urls when running under gunicorn
coreybrett at gmail.com
Thu Oct 15 16:04:01 CEST 2015
So I added "SERVER_NAME" to my config, and it did change the urls
produced by url_for.
It also broke my app completely and made all links produce 404 errors.
I don't know the answer to this problem.
I would take a look at...
On Wed, Oct 14, 2015 at 7:46 PM, S McGraw <smcg4191 at mtneva.com> wrote:
> 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.)
> On 10/13/2015 01:00 PM, Corey Boyle wrote:
>> I think what you are looking for is the "APPLICATION_ROOT" config item.
>> 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:
>>> 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
> Flask mailing list
> Flask at python.org
More information about the Flask