librelist archives

« back to archive

FastCGI and url_for

FastCGI and url_for

From:
Sajith Wickramasekara
Date:
2010-12-17 @ 02:38
Hi,

I have deployed an application using FastCGI on Apache. However, I would
like to generate URLs that do _not_ include the fcgi file. For example, in
my template, if I call url_for('index'), instead of generating
http://www.myapp.com/index it generates
http://www.myapp.com/myapplication.fcgi/index. How can I instruct it to
perform otherwise? It is worth noting that going to
http://www.myapp.com/index does work because I have taken the appropriate
steps using mod_rewrite. I just would prefer not to have to write URLs by
hand in my templates.

Thanks!

Re: [flask] FastCGI and url_for

From:
Simon Sapin
Date:
2010-12-17 @ 07:20
Le 17/12/2010 11:38, Sajith Wickramasekara a écrit :
> Hi,
>
> I have deployed an application using FastCGI on Apache. However, I 
> would like to generate URLs that do _not_ include the fcgi file. For 
> example, in my template, if I call url_for('index'), instead of 
> generating http://www.myapp.com/index it generates 
> http://www.myapp.com/myapplication.fcgi/index. How can I instruct it 
> to perform otherwise? It is worth noting that going to 
> http://www.myapp.com/index does work because I have taken the 
> appropriate steps using mod_rewrite. I just would prefer not to have 
> to write URLs by hand in my templates.
>
> Thanks!

Hi,

I’d try something like this: (not tested... nor proved correct :))

def strip_suffix(app, suffix):
def wrapped_app(environ, start_response):
if environ['SCRIPT_NAME'].endswith(suffix):
environ['SCRIPT_NAME'] = environ['SCRIPT_NAME'][:-len(suffix)]
return app(environ, start_response)
return wrapped_app

app.wsgi_app = strip_suffix(app.wsgi_app, '/myapplication.fcgi')

If it doesn’t work, log environ['SCRIPT_NAME'] and environ['PATH_INFO'] 
to see what’s going on.

Regards,
-- 
Simon Sapin