Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list the files in a static directory?

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!

like image 788
Martin Avatar asked Jan 25 '09 03:01

Martin


People also ask

Where are static files stored?

Static files are stored within the project's web root directory. The default directory is {content root}/wwwroot , but it can be changed with the UseWebRoot method. For more information, see Content root and Web root.

How static files are served?

Static files are typically files such as scripts, CSS files, images, etc... that aren't server-generated, but must be sent to the browser when requested. If node. js is your web server, it does not serve any static files by default, you must configure it to serve the static content you want it to serve.

What are static files?

What Are Static Files? Static files are files that don't change when your application is running. These files do a lot to improve your application, but they aren't dynamically generated by your Python web server like a usual HTML response.

How does django manage static files?

Configuring static filesMake sure that django.contrib.staticfiles is included in your INSTALLED_APPS . In your templates, use the static template tag to build the URL for the given relative path using the configured STATICFILES_STORAGE . Store your static files in a folder called static in your app.


2 Answers

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.

like image 127
David Avatar answered Oct 20 '22 16:10

David


Here´s a project that let you browse your static files: http://code.google.com/p/appfilesbrowser/

And here is must see list of recipes for appengine: http://appengine-cookbook.appspot.com/ (I found about that project here sometime ago)

like image 37
Tiago Avatar answered Oct 20 '22 17:10

Tiago