문제

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?

도움이 되었습니까?

해결책

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top