views:

32

answers:

1

How do I serve files from an arbitrary directory with Turbogears2?

I have a database with the local path, e.g. /home/myuser/tg2env/MyProject/myproject/files/somefile.jpg

tg.url seems to only be able to serve things from the public directory.

Is there a widget available, or do I need to write some sort of DownloadController?

A: 

Ok, I use this and it seems to work.

Anybody have a better opinion?

@expose()
@allow_only(predicates.not_anonymous())
def download(self):
    import paste.fileapp
    f = paste.fileapp.FileApp(filepath)
    from tg import use_wsgi_app
    return use_wsgi_app(f)
Lionel