librelist archives

« back to archive

Issue with url_for on cherokee + uwsgi

Issue with url_for on cherokee + uwsgi

From:
Julien C.
Date:
2011-01-25 @ 13:30
Hi,

I'm trying to deploy my app on cherokee web server with uwsgi. It's 
working but I have a problem with the url_for.

for example :

*when I visit  url : http://www.domain.tld/*

{{ url_for('static', filename='style.css') }} -> /static/style.css
{{ url_for('hello') }} -> /hello

*when I visit  url : http://www.domain.tld/hello*

{{ url_for('static', filename='style.css') }} -> /hello/static/style.css
{{ url_for('hello') }} -> /hello/hello

==============================================

I don't know how and where you can correct this :
- bug or normal behavior ??
- cherokee, uwsgi, flask ??

regards,

Julien C.

Re: [flask] Issue with url_for on cherokee + uwsgi

From:
Armin Ronacher
Date:
2011-01-25 @ 23:19
Hi,

On 2011-01-25 2:30 PM, Julien C. wrote:
> I don't know how and where you can correct this :
> - bug or normal behavior ??
> - cherokee, uwsgi, flask ??
It's certainly not Flask, it might be a side effect of how you are 
configuring your webserver.  The problem is that SCRIPT_NAME / PATH_INFO 
are wrong in your configuration.  Write yourself a middleware that 
rewrites SCRIPT_NAME / PATH_INFO accordingly or set your webserver to 
emit the correct values.

Check the mailinglist archives: http://bit.ly/ghaMmB


Regards,
Armin

Re: [flask] Issue with url_for on cherokee + uwsgi

From:
Nick Martin
Date:
2011-01-26 @ 00:43
Hi,

There is a nice bit of middleware for this kind of thing, 
paste.deploy.config.PrefixMiddleware. I haven't tried it with Flask yet 
but it works nicely for Pylons apps, where you want to provide a prefix 
for the app to the web server.

Best

Nick


On 25 Jan 2011, at 23:19, Armin Ronacher wrote:

> Hi,
> 
> On 2011-01-25 2:30 PM, Julien C. wrote:
>> I don't know how and where you can correct this :
>> - bug or normal behavior ??
>> - cherokee, uwsgi, flask ??
> It's certainly not Flask, it might be a side effect of how you are 
> configuring your webserver.  The problem is that SCRIPT_NAME / PATH_INFO 
> are wrong in your configuration.  Write yourself a middleware that 
> rewrites SCRIPT_NAME / PATH_INFO accordingly or set your webserver to 
> emit the correct values.
> 
> Check the mailinglist archives: http://bit.ly/ghaMmB
> 
> 
> Regards,
> Armin

Re: [flask] Issue with url_for on cherokee + uwsgi

From:
Julien
Date:
2011-01-26 @ 06:44
Ok, I will take a look.

Thank's.

Julien.

On 26/01/2011 01:43, Nick Martin wrote:
> Hi,
>
> There is a nice bit of middleware for this kind of thing, 
paste.deploy.config.PrefixMiddleware. I haven't tried it with Flask yet 
but it works nicely for Pylons apps, where you want to provide a prefix 
for the app to the web server.
>
> Best
>
> Nick
>
>
> On 25 Jan 2011, at 23:19, Armin Ronacher wrote:
>
>> Hi,
>>
>> On 2011-01-25 2:30 PM, Julien C. wrote:
>>> I don't know how and where you can correct this :
>>> - bug or normal behavior ??
>>> - cherokee, uwsgi, flask ??
>> It's certainly not Flask, it might be a side effect of how you are
>> configuring your webserver.  The problem is that SCRIPT_NAME / PATH_INFO
>> are wrong in your configuration.  Write yourself a middleware that
>> rewrites SCRIPT_NAME / PATH_INFO accordingly or set your webserver to
>> emit the correct values.
>>
>> Check the mailinglist archives: http://bit.ly/ghaMmB
>>
>>
>> Regards,
>> Armin
>
>

Re: [flask] Issue with url_for on cherokee + uwsgi

From:
Jonathan Chen
Date:
2011-01-26 @ 03:56
Just to add my little tidbit. Isn't usually recommended in production to not
use url_for?

Thanks,

~Jonathan C.


On Tue, Jan 25, 2011 at 4:43 PM, Nick Martin <iamntmartin@googlemail.com>wrote:

> Hi,
>
> There is a nice bit of middleware for this kind of thing,
> paste.deploy.config.PrefixMiddleware. I haven't tried it with Flask yet but
> it works nicely for Pylons apps, where you want to provide a prefix for the
> app to the web server.
>
> Best
>
> Nick
>
>
> On 25 Jan 2011, at 23:19, Armin Ronacher wrote:
>
> > Hi,
> >
> > On 2011-01-25 2:30 PM, Julien C. wrote:
> >> I don't know how and where you can correct this :
> >> - bug or normal behavior ??
> >> - cherokee, uwsgi, flask ??
> > It's certainly not Flask, it might be a side effect of how you are
> > configuring your webserver.  The problem is that SCRIPT_NAME / PATH_INFO
> > are wrong in your configuration.  Write yourself a middleware that
> > rewrites SCRIPT_NAME / PATH_INFO accordingly or set your webserver to
> > emit the correct values.
> >
> > Check the mailinglist archives: http://bit.ly/ghaMmB
> >
> >
> > Regards,
> > Armin
>
>

Re: [flask] Issue with url_for on cherokee + uwsgi

From:
Aaron Kavlie
Date:
2011-01-26 @ 04:24
I wouldn't think so. That's likely all over your templates, and it's good to
not hard-code URLs.

What is not recommended in production is hosting your static media through
Flask.

On Tue, Jan 25, 2011 at 8:56 PM, Jonathan Chen <tamasiaina@gmail.com> wrote:

> Just to add my little tidbit. Isn't usually recommended in production to
> not use url_for?
>
> Thanks,
>
> ~Jonathan C.
>
>
>
> On Tue, Jan 25, 2011 at 4:43 PM, Nick Martin <iamntmartin@googlemail.com>wrote:
>
>> Hi,
>>
>> There is a nice bit of middleware for this kind of thing,
>> paste.deploy.config.PrefixMiddleware. I haven't tried it with Flask yet but
>> it works nicely for Pylons apps, where you want to provide a prefix for the
>> app to the web server.
>>
>> Best
>>
>> Nick
>>
>>
>> On 25 Jan 2011, at 23:19, Armin Ronacher wrote:
>>
>> > Hi,
>> >
>> > On 2011-01-25 2:30 PM, Julien C. wrote:
>> >> I don't know how and where you can correct this :
>> >> - bug or normal behavior ??
>> >> - cherokee, uwsgi, flask ??
>> > It's certainly not Flask, it might be a side effect of how you are
>> > configuring your webserver.  The problem is that SCRIPT_NAME / PATH_INFO
>> > are wrong in your configuration.  Write yourself a middleware that
>> > rewrites SCRIPT_NAME / PATH_INFO accordingly or set your webserver to
>> > emit the correct values.
>> >
>> > Check the mailinglist archives: http://bit.ly/ghaMmB
>> >
>> >
>> > Regards,
>> > Armin
>>
>>
>


-- 
freelance web services
aaron.kavlie.net

Re: [flask] Issue with url_for on cherokee + uwsgi

From:
Julien
Date:
2011-01-26 @ 07:01
Yes, and it will be great if Flask have a simple function like *url_for* 
for building url for static files.
By default on /static path/folder and serve by Flask on developpement. 
Or use a configuration value which indicate the url of the static files :
app.config['STATIC_URL'] = 'http://static.domain.tld' # default : '/static'

today, you have to rewrite all yours templates to do this.

Julien C.


On 26/01/2011 05:24, Aaron Kavlie wrote:
> I wouldn't think so. That's likely all over your templates, and it's 
> good to not hard-code URLs.
>
> What is not recommended in production is hosting your static media 
> through Flask.
>
> On Tue, Jan 25, 2011 at 8:56 PM, Jonathan Chen <tamasiaina@gmail.com 
> <mailto:tamasiaina@gmail.com>> wrote:
>
>     Just to add my little tidbit. Isn't usually recommended in
>     production to not use url_for?
>
>     Thanks,
>
>     ~Jonathan C.
>

Re: [flask] Issue with url_for on cherokee + uwsgi

From:
Thadeus Burgess
Date:
2011-01-26 @ 15:58
I usually define a ``static`` function and use that... for most of my
applications it is just a wrapper around url_for.... in your case you can
make it look at the current_app.config....

def static(filename):
   return current_app.config['STATIC_SERVER'] + '/' + filename

in my cases I just use

def static(filename):
   return url_for('.static', filename=filename)

--
Thadeus




On Wed, Jan 26, 2011 at 1:01 AM, Julien <jc63@free.fr> wrote:

> Yes, and it will be great if Flask have a simple function like *url_for*
> for building url for static files.
> By default on /static path/folder and serve by Flask on developpement.
> Or use a configuration value which indicate the url of the static files :
> app.config['STATIC_URL'] = 'http://static.domain.tld' # default :
> '/static'
>
> today, you have to rewrite all yours templates to do this.
>
> Julien C.
>
>
> On 26/01/2011 05:24, Aaron Kavlie wrote:
> > I wouldn't think so. That's likely all over your templates, and it's
> > good to not hard-code URLs.
> >
> > What is not recommended in production is hosting your static media
> > through Flask.
> >
> > On Tue, Jan 25, 2011 at 8:56 PM, Jonathan Chen <tamasiaina@gmail.com
> > <mailto:tamasiaina@gmail.com>> wrote:
> >
> >     Just to add my little tidbit. Isn't usually recommended in
> >     production to not use url_for?
> >
> >     Thanks,
> >
> >     ~Jonathan C.
> >
>
>

Re: [flask] Issue with url_for on cherokee + uwsgi

From:
Julien
Date:
2011-01-27 @ 05:13
ok,

but how can you use it in template ?

Something similar:

def static_file(filename):
     return  "%s/%s" % (app.config['STATIC_SERVER'] , filename)

...

app.jinja_env.globals.update(
     static=static_file
)

in template:
<link rel="stylesheet" type="text/css" href="{{ static('css/style.css') 
}}" />

regards

Julien C.


On 26/01/2011 16:58, Thadeus Burgess wrote:
> I usually define a ``static`` function and use that... for most of my 
> applications it is just a wrapper around url_for.... in your case you 
> can make it look at the current_app.config....
>
> def static(filename):
>    return current_app.config['STATIC_SERVER'] + '/' + filename
>
> in my cases I just use
>
> def static(filename):
>    return url_for('.static', filename=filename)
>
> --
> Thadeus
>
>
>
>
> On Wed, Jan 26, 2011 at 1:01 AM, Julien <jc63@free.fr 
> <mailto:jc63@free.fr>> wrote:
>
>     Yes, and it will be great if Flask have a simple function like
>     *url_for*
>     for building url for static files.
>     By default on /static path/folder and serve by Flask on developpement.
>     Or use a configuration value which indicate the url of the static
>     files :
>     app.config['STATIC_URL'] = 'http://static.domain.tld' # default :
>     '/static'
>
>     today, you have to rewrite all yours templates to do this.
>
>     Julien C.
>
>
>     On 26/01/2011 05:24, Aaron Kavlie wrote:
>     > I wouldn't think so. That's likely all over your templates, and it's
>     > good to not hard-code URLs.
>     >
>     > What is not recommended in production is hosting your static media
>     > through Flask.
>     >
>     > On Tue, Jan 25, 2011 at 8:56 PM, Jonathan Chen
>     <tamasiaina@gmail.com <mailto:tamasiaina@gmail.com>
>     > <mailto:tamasiaina@gmail.com <mailto:tamasiaina@gmail.com>>> wrote:
>     >
>     >     Just to add my little tidbit. Isn't usually recommended in
>     >     production to not use url_for?
>     >
>     >     Thanks,
>     >
>     >     ~Jonathan C.
>     >
>
>

Re: [flask] Issue with url_for on cherokee + uwsgi

From:
Thadeus Burgess
Date:
2011-01-27 @ 06:05
yes
--
Thadeus




On Wed, Jan 26, 2011 at 11:13 PM, Julien <jc63@free.fr> wrote:

> ok,
>
> but how can you use it in template ?
>
> Something similar:
>
> def static_file(filename):
>     return  "%s/%s" % (app.config['STATIC_SERVER'] , filename)
>
> ...
>
> app.jinja_env.globals.update(
>     static=static_file
> )
>
> in template:
> <link rel="stylesheet" type="text/css" href="{{ static('css/style.css')
> }}" />
>
> regards
>
> Julien C.
>
>
> On 26/01/2011 16:58, Thadeus Burgess wrote:
> > I usually define a ``static`` function and use that... for most of my
> > applications it is just a wrapper around url_for.... in your case you
> > can make it look at the current_app.config....
> >
> > def static(filename):
> >    return current_app.config['STATIC_SERVER'] + '/' + filename
> >
> > in my cases I just use
> >
> > def static(filename):
> >    return url_for('.static', filename=filename)
> >
> > --
> > Thadeus
> >
> >
> >
> >
> > On Wed, Jan 26, 2011 at 1:01 AM, Julien <jc63@free.fr
> > <mailto:jc63@free.fr>> wrote:
> >
> >     Yes, and it will be great if Flask have a simple function like
> >     *url_for*
> >     for building url for static files.
> >     By default on /static path/folder and serve by Flask on
> developpement.
> >     Or use a configuration value which indicate the url of the static
> >     files :
> >     app.config['STATIC_URL'] = 'http://static.domain.tld' # default :
> >     '/static'
> >
> >     today, you have to rewrite all yours templates to do this.
> >
> >     Julien C.
> >
> >
> >     On 26/01/2011 05:24, Aaron Kavlie wrote:
> >     > I wouldn't think so. That's likely all over your templates, and
> it's
> >     > good to not hard-code URLs.
> >     >
> >     > What is not recommended in production is hosting your static media
> >     > through Flask.
> >     >
> >     > On Tue, Jan 25, 2011 at 8:56 PM, Jonathan Chen
> >     <tamasiaina@gmail.com <mailto:tamasiaina@gmail.com>
> >     > <mailto:tamasiaina@gmail.com <mailto:tamasiaina@gmail.com>>>
> wrote:
> >     >
> >     >     Just to add my little tidbit. Isn't usually recommended in
> >     >     production to not use url_for?
> >     >
> >     >     Thanks,
> >     >
> >     >     ~Jonathan C.
> >     >
> >
> >
>
>

Re: [flask] Issue with url_for on cherokee + uwsgi

From:
Julien
Date:
2011-01-25 @ 20:35
I've noticed one more thing. When I had a route like this :
======================
@mod.route('/search')
def search():
...

on http://www.domain.tld/
{{ url_for('static', filename='style.css') }} -> /static/style.css

on http://www.domain.tld/search
{{ url_for('static', filename='style.css') }} -> /search/static/style.css
(why /search)
======================
but if I do:
@mod.route('/search/')
def search():
...

on http://www.domain.tld/search/
{{ url_for('static', filename='style.css') }} -> /static/style.css
======================
and with:

but if I do:
@mod.route('/show/<pid>')
def show(pid):
...

on http://www.domain.tld/show/10
{{ url_for('static', filename='style.css') }} -> /static/style.css
======================

I could change all my route but It should work with no extra / after ?

any idea??

Julien.



On 25/01/2011 14:30, Julien C. wrote:
> Hi,
>
> I'm trying to deploy my app on cherokee web server with uwsgi. It's 
> working but I have a problem with the url_for.
>
> for example :
>
> *when I visit  url : http://www.domain.tld/*
>
> {{ url_for('static', filename='style.css') }} -> /static/style.css
> {{ url_for('hello') }} -> /hello
>
> *when I visit  url : http://www.domain.tld/hello*
>
> {{ url_for('static', filename='style.css') }} -> /hello/static/style.css
> {{ url_for('hello') }} -> /hello/hello
>
> ==============================================
>
> I don't know how and where you can correct this :
> - bug or normal behavior ??
> - cherokee, uwsgi, flask ??
>
> regards,
>
> Julien C.

Re: [flask] Issue with url_for on cherokee + uwsgi

From:
Peter Ward
Date:
2011-01-25 @ 21:07
Does url_for('.static', filename='style.css')work?

On 26 January 2011 07:35, Julien <jc63@free.fr> wrote:

>  I've noticed one more thing. When I had a route like this :
> ======================
> @mod.route('/search')
> def search():
> ...
>
> on http://www.domain.tld/
>
> {{ url_for('static', filename='style.css') }} -> /static/style.css
>
> on http://www.domain.tld/search
> {{ url_for('static', filename='style.css') }} -> /search/static/style.css
> (why /search)
> ======================
> but if I do:
> @mod.route('/search/')
> def search():
> ...
>
> on http://www.domain.tld/search/
>
> {{ url_for('static', filename='style.css') }} -> /static/style.css
> ======================
> and with:
>
> but if I do:
> @mod.route('/show/<pid>')
> def show(pid):
> ...
>
> on http://www.domain.tld/show/10
>
> {{ url_for('static', filename='style.css') }} -> /static/style.css
> ======================
>
> I could change all my route but It should work with no extra / after ?
>
> any idea??
>
> Julien.
>
>
>
>
> On 25/01/2011 14:30, Julien C. wrote:
>
> Hi,
>
> I'm trying to deploy my app on cherokee web server with uwsgi. It's working
> but I have a problem with the url_for.
>
> for example :
>
> *when I visit  url : http://www.domain.tld/*
>
> {{ url_for('static', filename='style.css') }} -> /static/style.css
> {{ url_for('hello') }} -> /hello
>
> *when I visit  url : http://www.domain.tld/hello*
>
> {{ url_for('static', filename='style.css') }} -> /hello/static/style.css
> {{ url_for('hello') }} -> /hello/hello
>
> ==============================================
>
> I don't know how and where you can correct this :
> - bug or normal behavior ??
> - cherokee, uwsgi, flask ??
>
> regards,
>
> Julien C.
>
>
>


-- 
Peter Ward
http://flowblok.id.au/
BCST III, Sydney University

Re: [flask] Issue with url_for on cherokee + uwsgi

From:
Julien
Date:
2011-01-25 @ 22:27
No it produce the same wrong url

On 25/01/2011 22:07, Peter Ward wrote:
> Does url_for('.static', filename='style.css')work?
>
> On 26 January 2011 07:35, Julien <jc63@free.fr <mailto:jc63@free.fr>> 
> wrote:
>
>     I've noticed one more thing. When I had a route like this :
>     ======================
>     @mod.route('/search')
>     def search():
>     ...
>
>     on http://www.domain.tld/
>
>     {{ url_for('static', filename='style.css') }} -> /static/style.css
>
>     on http://www.domain.tld/search
>     {{ url_for('static', filename='style.css') }} ->
>     /search/static/style.css
>     (why /search)
>     ======================
>     but if I do:
>     @mod.route('/search/')
>     def search():
>     ...
>
>     on http://www.domain.tld/search/
>
>     {{ url_for('static', filename='style.css') }} -> /static/style.css
>     ======================
>     and with:
>
>     but if I do:
>     @mod.route('/show/<pid>')
>     def show(pid):
>     ...
>
>     on http://www.domain.tld/show/10
>
>     {{ url_for('static', filename='style.css') }} -> /static/style.css
>     ======================
>
>     I could change all my route but It should work with no extra / after ?
>
>     any idea??
>
>     Julien.
>
>
>
>
>     On 25/01/2011 14:30, Julien C. wrote:
>>     Hi,
>>
>>     I'm trying to deploy my app on cherokee web server with uwsgi.
>>     It's working but I have a problem with the url_for.
>>
>>     for example :
>>
>>     *when I visit  url : http://www.domain.tld/*
>>
>>     {{ url_for('static', filename='style.css') }} -> /static/style.css
>>     {{ url_for('hello') }} -> /hello
>>
>>     *when I visit  url : http://www.domain.tld/hello*
>>
>>     {{ url_for('static', filename='style.css') }} ->
>>     /hello/static/style.css
>>     {{ url_for('hello') }} -> /hello/hello
>>
>>     ==============================================
>>
>>     I don't know how and where you can correct this :
>>     - bug or normal behavior ??
>>     - cherokee, uwsgi, flask ??
>>
>>     regards,
>>
>>     Julien C.
>
>
>
>
> -- 
> Peter Ward
> http://flowblok.id.au/
> BCST III, Sydney University