can somebody give me a hint on how static content is served? I need to "embed"
the TG2-app into an existing wsgi-app below a certain path - and obviously
serving e.g. the CSS fails miserably. There was the old way of using tg.url
and server.webpath (or such) - any such facility available?
Diez
http://pythonpaste.org/modules/cascade.html
Along with the paste StaticURLParser and StaticJavascripts (from pylons)
It's configured like this.
So configuring this should be as simple as setting up the proper info
in the ini file.
javascripts_app = StaticJavascripts()
static_app = StaticURLParser(config['pylons.paths']['static_files'])
app = Cascade([static_app, javascripts_app, app])
Let me know if we need to expose some more configuration information
to the user app, all of this was changed sort-of-recently when we
cleaned up middleware.py.
--
Mark Ramm-Christensen
email: mark at compoundthinking dot com
blog: www.compoundthinking.com/blog
Ahh! That's interesting - and explains some stuff I've seen while
source-level-debugging. The Cascade is interersting for me...
And of course the current implementation is a bit warty::
# Static files (If running in production, and Apache or another web
# server is handling this static content, remove the following 3
lines)
javascripts_app = StaticJavascripts()
static_app = StaticURLParser(config['pylons.paths']['static_files'])
app = Cascade([static_app, javascripts_app, app])
return app
Obviously we want that configurable.
I will open a ticket & try and install TG2 from SVN, so that I can propose a
solution for this. I guess the best solution would be to have the above code
in <myapplication>/controllers/__init__.py or some such location - or the
config/middleware.py, that might even be better.
Diez
I created a ticket:
http://trac.turbogears.org/ticket/1898#preview
Diez
The question is: where to set this? I tried
[server:main]
in development.ini, and it puked on me about an unknown argument.
I then stuffed into
[app:main]
server.webpath = /collaborate
also in development.ini - but the access above reading "server.webpath"
doesn't work for me then. The value appears as this:
pylons.config.app_conf.get('server.webpath')
So... where is that supposed to be, and is this a bug?
Diez
Ok, I created a patch for the ticket. It includes rewrites of tg.middleware an
middleware.py_tmpl (so that the app decides on the static rewriting), and
tg.url-enclosing of hopefully all relevant template-urls.
Before I attach that, I have some questions I need to have answered:
- where does the sever.webpath config option actually go? Currently, I've put
it as this in my development.ini::
[app:main]
use = egg:AuthenticationTest
full_stack = true
#lang = ru
cache_dir = %(here)s/data
beaker.session.key = authenticationtest
beaker.session.secret = somesecret
server.webpath = /collaborate
It is accessed using
pylons.config['app_cfg']['sever.webpath']
- how is server.webpath supposed to be used? The question arises because of
the following considerations:
1) if the TG2-app is one of possibly several below a WSGI-app "mounted" to
server.webpath, we need to rewrite the PATH_INFO prior to all requests to
remove the server.webpath. I've done that, and it makes additionally
adjustments to tg.ext.repoze.who necessary (done them also) because of the
generated /login and related urls. These need to be prepended with
server.webpath.
2) if the TG2-app is below server.webpath in an Apache-environment, it
*might* be possible to use mod_rewrite to strip of the path-prefix for us,
thus only the generated urls must
I've done everything for 1). If 2) is an actual scenario we want to work with,
it might be necessary to introduce another config-variable called
server.strip_webpath or so, that controls the adjustment of PATH_INFO.
Diez
I think that we should be relying on SCRIPT_NAME in the environ being
set properly, and it looks like I need to patch tg.url to make that
work right.
When serving behing apache or another server that does the right
thing, the SCRIPT_NAME should automatically be set correctly. When
it's not we'll need to use some little middleware that sets it right
before we get into the tg2 app.
Inside a TG2 app, we can use request.application_url to get the URL
including the host name and SCRIPT_NAME but with no PATH_INFO or query
string.
--