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.
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With