Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

request.path and url_for don't match up in Flask under mod_wsgi

In Flask, is there a way to get the request.path that includes any "decorations" that WSGI or something else may add on?

Running in the test mode (just on port 5000), my request.path and url_for('settings') match up just fine, but once under WSGI, as expected, my url_for('settings') becomes /manage/settings/, but the request.path yeilds /settings/.

I have the following in my httpd.conf and am working on moving an application from development into a live site.

WSGIScriptAlias /manage /sw/servermanager/servermanager.wsgi
WSGIDaemonProcess servermgr user=user group=grp threads=4
<Directory /sw/servermanager>
    WSGIProcessGroup servermgr
    WSGIApplicationGroup %{GLOBAL}
    WSGIScriptReloading On
    Order deny,allow
    Allow from all
</Directory>

I like the idea of having the templates be pretty generic and then display the navigation information on the fly using CSS. I've used the technique provided in this answer to structure my views to this point, but the issue arises when I add mod_wsgi into the equation.

I took a look around the request object and didn't see as much as I'd like other than possibly using the url_rule but then the parameters evaded me.

Just for good measure, a link for the WSGI Script that I'm using: https://github.com/FernFerret/servermanager/blob/master/servermanager.wsgi

I'd also be interested in the documentation for the request object, I found my way around it by using the built in debugger and help(request).

EDIT: I should say, that the urls don't match up under Apache running mod_wsgi.

like image 544
fernferret Avatar asked Feb 26 '13 15:02

fernferret


People also ask

What is url_for function in flask?

url_for in Flask is used for creating a URL to prevent the overhead of having to change URLs throughout an application (including in templates). Without url_for , if there is a change in the root URL of your app then you have to change it in every page where the link is present.

What is url_for?

The url_for() function generates the URL to a view based on a name and arguments. The name associated with a view is also called the endpoint, and by default it's the same as the name of the view function.


1 Answers

That's a feature, not a bug. Check out documentation for the URL-related attributes on the request and for the request object itself.

You may want to use request.script_root + request.path.

like image 64
gioi Avatar answered Nov 14 '22 21:11

gioi