Найти - Пользователи
Полная версия: [webpy] поддиректории
Начало » Web » [webpy] поддиректории
1
aspire89
Есть папка stuff, а в ней js, css и прочеее, все отдается нормально.
#!/usr/bin/env python
import web, os
urls = ('/','root','/stuff/(.*)', 'stuff')
app = web.application(urls, globals())
render = web.template.render('templates/')
class root:
    def GET(self):                
            return render.mytitle("test")
class stuff:
    def GET(self,name):
        ext = name.split(".")[-1]
        cType = {
            "js":"text/javascript",
            "css":"text/css"
                }
        if name in os.listdir('stuff'):
            web.header("Content-Type", cType[ext])
            return open('stuff/%s'%name,"rb").read()
        else:
            raise web.notfound()
 
if __name__ == "__main__":
        app.run()

Если в папке stuff создать любую папку и попытаться из нее получить файл, то получим 404 ошибку, и в браузере not found. Что дописать, чтобы исправить?
aspire89
Проблема решилась переносом в /static
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB