Handles Resources

28 views
Skip to first unread message

Luca Verardi

unread,
Mar 23, 2015, 4:11:30 AM3/23/15
to turbo...@googlegroups.com
Hello everybody,
I have a question concerning how TurboGears2 handles resources.
This is my server's address:

http://root.myproject.com/myproject

External resources are instead given this address:

http://root.myproject.com/tw2/resources/myproject/public/javascript/jquery-1.11.1.min.js

How do I tell TG2 to go look in 
"http://root.myproject.com/myproject/tw2/[...]" instead of 
"http://root.myproject.com/tw2/[...]"?

Thanks

Alessandro Molina

unread,
Mar 24, 2015, 8:11:52 AM3/24/15
to TurboGears
custom_tw2_config.res_prefix is the option to tell TW2 where to serve its resources, 
but I suppose that you are mounting the whole project in a subpath, in such case it should be handled by SCRIPT_NAME but I didn't check it is properly managed by TW2.

--
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email to turbogears+...@googlegroups.com.
To post to this group, send email to turbo...@googlegroups.com.
Visit this group at http://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.

Luca Verardi

unread,
Mar 25, 2015, 7:07:15 AM3/25/15
to turbo...@googlegroups.com
Hello,

if I hardcode the address in app_cfg it works, although I really don't 
want to do that, as it could vary between servers. The problem is, by 
this point, the params from development.ini are not available yet. They 
become available AFTER make_base_app has been called, but by then all 
resources have already been bound to the default address. I've read the 
docs at 
http://turbogears.readthedocs.org/en/latest/turbogears/configuration/appconfig.html 
, but after countless failed attempts, I'm still stumped as to what to do.

Thanks


Il giorno martedì 24 marzo 2015 13:11:52 UTC+1, Alessandro Molina ha scritto:
custom_tw2_config.res_prefix is the option to tell TW2 where to serve its resources, 
but I suppose that you are mounting the whole project in a subpath, in such case it should be handled by SCRIPT_NAME but I didn't check it is properly managed by TW2.
On Mon, Mar 23, 2015 at 9:11 AM, Luca Verardi <luca.ve...@gmail.com> wrote:
Hello everybody,
I have a question concerning how TurboGears2 handles resources.
This is my server's address:

http://root.myproject.com/myproject

External resources are instead given this address:

http://root.myproject.com/tw2/resources/myproject/public/javascript/jquery-1.11.1.min.js

How do I tell TG2 to go look in 
"http://root.myproject.com/myproject/tw2/[...]" instead of 
"http://root.myproject.com/tw2/[...]"?

Thanks

--
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email to turbogears+unsubscribe@googlegroups.com.

Alessandro Molina

unread,
Mar 25, 2015, 7:38:42 PM3/25/15
to TurboGears
Sadly that is one of the shortcomings of the current configuration process, there are some options you can specify in .ini files and some that are only available from AppConfig. That dichotomy will be improved a bit by 2.3.5 and resolved by 2.4 which will make no difference between options loaded from config files and specified in app_cfg.

In the meanwhile, as custom_tw2_config is one of those options, you can work-around that by binding to the config_ready milestone (which signals that the .ini config has been read and merged into tg.config) and switch base_config.custom_tw2_config.script_name to the value you see in tg.config. That way the middleware will be properly configured with the value specified in .ini as you got it from tg.config after it contains the .ini values.

 

To unsubscribe from this group and stop receiving emails from it, send an email to turbogears+...@googlegroups.com.

Luca Verardi

unread,
Mar 27, 2015, 4:26:43 AM3/27/15
to turbo...@googlegroups.com
Ok i don't understand how its work config_ready.
Can you make me an example please?

Thanks

Alessandro Molina

unread,
Mar 27, 2015, 6:26:16 AM3/27/15
to TurboGears
Put inside your app_cfg.py something like:

def set_proper_tw2_scriptname():
    base_config.custom_tw2_config = {'script_name': tg.config['deployed_scriptname']}

from tg.configuration import milestones
milestones.config_ready.register(set_proper_tw2_scriptname)

Have not tested it at all so there might be typos or wrong variables but I hope it gets the idea.

Alessandro
Reply all
Reply to author
Forward
0 new messages