如何列出静态目录中的文件? [英] How to list the files in a static directory?

查看:100
本文介绍了如何列出静态目录中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google App Engine和Python,但无法列出静态目录的文件。以下是我目前使用的代码。



app.yaml

   -  url:/ data 
static_dir:data

Python代码列出文件

  myFiles = [] 
for root,dirs,files in os.path(os.path.join(os.path.dirname(__ file__),'data /')):
用于文件中的名称:
full_name = os.path.join(root,name )
myFiles.append('%s;%s\\\
'%(name,datetime.fromtimestamp(os.stat(full_name).st_mtime)))

当我在本地机器上运行此代码时,一切都可以。我在目录的根目录下有我的Python脚本,它将数据目录下的文件遍历。但是,当我上传并在GAE中运行完全相同的代码时,它不起作用。在我看来,我的应用程序的目录结构并未在Google App Engine中完全复制。 静态文件在哪里?



谢谢!

解决方案 div>

https://developers.google.com/appengine / docs / python / config / appconfig#python_app_yaml_Static_file_handlers



它们不在你认为的位置,GAE会将静态内容放入GoogleFS,相当于CDN。这个想法是,静态内容意味着直接提供给您的用户,而不是您可以操作的文件存储。此外,GAE有1K文件限制,如果你可以操纵你的静态文件存储,那么很难监管这条规则。


I am playing with Google App Engine and Python and I cannot list the files of a static directory. Below is the code I currently use.

app.yaml

- url: /data
  static_dir: data

Python code to list the files

myFiles = []
for root, dirs, files in os.walk(os.path.join(os.path.dirname(__file__), 'data/') ):
    for name in files:
        full_name = os.path.join(root, name)
        myFiles.append('%s;%s\n' % (name, datetime.fromtimestamp(os.stat(full_name).st_mtime)))

When I run this code locally on my machine, everything is alright. I have my Python script at the root of the directory and it walks the files under the data directory. However, when I upload and run the exact same code in GAE, it doesn`t work. It seems to me that the directory structure of my application is not exactly replicated in Google App Engine. Where are the static files?

Thanks!

解决方案

https://developers.google.com/appengine/docs/python/config/appconfig#Python_app_yaml_Static_file_handlers

They're not where you think they are, GAE puts static content into GoogleFS which is equivalent of a CDN. The idea is that static content is meant to be served directly to your users and not act as a file store you can manipulate. Furthermore GAE has 1K file limit and it would be difficult to police this rule if you could manipulate your static file store.

这篇关于如何列出静态目录中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆