turbogears2 and public/static folder

42 views
Skip to first unread message

Lukasz Szybalski

unread,
Nov 8, 2008, 3:32:33 PM11/8/08
to TurboGears
Hello,
In tg1 there was a static folder that you aliased in your apache configuration.
so at the end you got this setup:
http://localhost:8080/static/images/logo.png
http://localhost:8080/static/css/style.css


I see that in tg2 there is no such folder.

http://localhost:8080/images/logo.png
http://localhost:8080/css/style.css

Which configuration I need to change to add a prefix folder. I would
like to get something like this:
http://localhost:8080/public/images/logo.png
http://localhost:8080/public/css/style.css

What do I need to change?

Thanks,
Lucas


--
Turbogears2 Manual
http://lucasmanual.com/mywiki/TurboGears2
Bazaar and Launchpad
http://lucasmanual.com/mywiki/bzr

Diez B. Roggisch

unread,
Nov 9, 2008, 8:38:53 AM11/9/08
to turbo...@googlegroups.com
Lukasz Szybalski schrieb:

> Hello,
> In tg1 there was a static folder that you aliased in your apache configuration.
> so at the end you got this setup:
> http://localhost:8080/static/images/logo.png
> http://localhost:8080/static/css/style.css
>
>
> I see that in tg2 there is no such folder.
>
> http://localhost:8080/images/logo.png
> http://localhost:8080/css/style.css
>
> Which configuration I need to change to add a prefix folder. I would
> like to get something like this:
> http://localhost:8080/public/images/logo.png
> http://localhost:8080/public/css/style.css
>
> What do I need to change?

AFAIK (haven't quickstarted a TG2-app in a while & different resource
handling anyway) there actually *is* a public/-directory.

However, you can create aliases for apache for each directory - images,
css, whatever.

Diez

Lukasz Szybalski

unread,
Nov 9, 2008, 1:19:31 PM11/9/08
to turbo...@googlegroups.com


Imagine you are deploying 3 tg2 apps using apache and mod_wsgi. How
are you going to differentiate the alias for /images for the 3 apps?

Lucas

Diez B. Roggisch

unread,
Nov 9, 2008, 1:32:53 PM11/9/08
to turbo...@googlegroups.com
Lukasz Szybalski schrieb:

In the same way you disambiguate the three mod_wsgi-apps. Either by
common prefix, or by vhost. How else?

Diez

Lukasz Szybalski

unread,
Nov 9, 2008, 2:02:32 PM11/9/08
to turbo...@googlegroups.com

In tg1 I change the prefix of the static folder in configuration file
to static-myapp and in apache I alias static-myapp
/path..to..static..folder/static/.
Tg1 app knows that it needs to get images from localhost/static-myapp/
and not from localhost/static.
In tg2, as far as I know there is now way to tell my app that images
are not under /localhost/images but they are in localhost/images-myapp
?

How would you setup the common prefix you are talking about?

Thanks,
Lucas

Diez B. Roggisch

unread,
Nov 9, 2008, 4:27:10 PM11/9/08
to turbo...@googlegroups.com

where does the /localhost/ come from? In a TG2-app, there are
<myapp>/public/[css|javascript|images]-folders.

Those are referred to as

/css

/javascript

/images

So creating aliases for these is the same as for creating them for a
TG1-app. Yes, you need three of them - who cares?

> How would you setup the common prefix you are talking about?

server.webpath + usage of tg.url should do the trick.

Diez

Lukasz Szybalski

unread,
Nov 9, 2008, 9:37:42 PM11/9/08
to turbo...@googlegroups.com

Because its not as easy as you are describing it here.


Is there a similar functionality in tg2 as in app.cfg that describes:

[/static]
static_filter.on = True
static_filter.dir = "%(top_level_dir)s/static"

tg2 doesn't seem to have this section in there.

Lucas

Diez B. Roggisch

unread,
Nov 10, 2008, 3:19:42 AM11/10/08
to turbo...@googlegroups.com

Yes it is - just create *three* directory aliases, for each app of course.

To distinguish between different apps, either use vhosts (certainly the
best solution) or tg.url for rendering every url & set "server.webpath"
to create a common prefix for all urls in each application.

> Is there a similar functionality in tg2 as in app.cfg that describes:
>
> [/static]
> static_filter.on = True
> static_filter.dir = "%(top_level_dir)s/static"
>
> tg2 doesn't seem to have this section in there.

It has a static middleware which creates the three different prefixes.
The method setup_paths in tg.configuration determines how these are set
up. You could overload that method, or provide a different config
through self.paths. A look into the source reveals that - which you
should certainly risk, given the beta-status of tg :)

Diez

Lukasz Szybalski

unread,
Nov 10, 2008, 9:58:04 AM11/10/08
to turbo...@googlegroups.com

Do you have a sample vhost configuration that would allow me to do:

example.com/myapp
and one separate for
myapp.example.com

> or tg.url for rendering every url & set "server.webpath"

Is server.webpath available in tg2? Where do I set it? In tg1 I was
setting it in mod_wsgi config file only, but from the examples I seen
on tg2/pylons nowhere does it mention where to set it.


> to create a common prefix for all urls in each application.
>
>> Is there a similar functionality in tg2 as in app.cfg that describes:
>>
>> [/static]
>> static_filter.on = True
>> static_filter.dir = "%(top_level_dir)s/static"
>>
>> tg2 doesn't seem to have this section in there.
>
> It has a static middleware which creates the three different prefixes.
> The method setup_paths in tg.configuration determines how these are set
> up. You could overload that method, or provide a different config
> through self.paths. A look into the source reveals that - which you
> should certainly risk, given the beta-status of tg :)

Well, If you are saying that vhost / webpath will work and you have
tested it then I don't think I'll need it, hard to say. The fact that
it was available in tg1 seems to me that somebody needed it one point
or another.

Lucas

Lukasz Szybalski

unread,
Nov 13, 2008, 10:50:55 PM11/13/08
to turbo...@googlegroups.com
> To distinguish between different apps, either use vhosts (certainly the
> best solution) or tg.url for rendering every url & set "server.webpath"
> to create a common prefix for all urls in each application.

Do you know how can I set server.webpath in wsgi scipt?

Thanks,
Lucas

Graham Dumpleton

unread,
Nov 14, 2008, 4:14:38 AM11/14/08
to TurboGears
You should not need to set server.webpath. A well behaved WSGI
application would automatically derive the application mount point
from the value of SCRIPT_NAME passed by the underly WSGI adapter to
the WSGI application. If TG2 doesn't do this, then it is broken.

Thus, you should just need to say:

WSGIScriptAlias /subapp /some/path/subapp.wsgi

Alias /subapp/images /some/otherpath/subapp/static/images
Alias /subapp/css /some/otherpath/subapp/static/css

WSGIScriptAlias / /some/path/rootapp.wsgi

Alias /images /some/otherpath/rootapp/static/images
Alias /css /some/otherpath/rootapp/static/css

and it should work. If not, then as I said, TG2 is arguably doing the
wrong thing, or way that URLs within pages for images and css are
being constructed wrongly.

See old discussion.

http://groups.google.com/group/turbogears/browse_frm/thread/b8978e071762428d

I believe that maintenance happening on older TG1 derived versions may
have added a patch for this to subversion. Whether it has been
released in a TG1 version I am not sure.

Graham

Lukasz Szybalski

unread,
Nov 14, 2008, 9:54:02 AM11/14/08
to turbo...@googlegroups.com
Thanks,
I've added a ticket to trac:
http://trac.turbogears.org/ticket/2033

Would that require only middleware.py to change by added the value of
script name SCRIPT_NAME in front of any image or css folders ?

Lucas

Lukasz Szybalski

unread,
Nov 17, 2008, 11:38:37 PM11/17/08
to turbo...@googlegroups.com
Can somebody tell me how am I suppose to use the url encoding in tg2?

How do you encode urls in a root.py and how do you encode it in a template?

url_for ??? What needs to be imported how do I encode a url like
"/image/myimage.png"?

Thanks,
Lucas

Lukasz Szybalski

unread,
Nov 18, 2008, 1:15:41 AM11/18/08
to turbo...@googlegroups.com
Hello,

It seems as default templates don't use url_for. I didn't check the
identity templates but here is a way to fix this:

FIX:
the default templates will need to change
In lib/helpers.py the following will need to be imported:
from routes import url_for

In master.html a css stylesheet will need to be changed to:
<link rel="stylesheet" type="text/css" media="screen"
href="${h.url_for('/css/style.css')}" />

footer.html:
<img src="${h.url_for('/images/under_the_hood_blue.png')}" alt="TurboGears" />


header.html
<img src="${h.url_for('/images/logo.png')}" alt="TG2!"/>

possibly login.html

Thanks,
Lucas

Lukasz Szybalski

unread,
Nov 18, 2008, 9:35:08 AM11/18/08
to turbo...@googlegroups.com
I've uploaded the patch that fixed this.

http://trac.turbogears.org/ticket/2033#comment:5

Could somebody commit it.

Thanks,
Lucas

--

Reply all
Reply to author
Forward
0 new messages