开发者

What's the path to files in myapp/static on AppEngine

I want to add objects based on information of a .csv file (call it info.csv) to my models when the project is init开发者_StackOverflowiated on Google appengine (I'm using django-nonrel).

My approach is to write a dedicated util.py in myapp, which is called in view.py. util.py is supposed to read info.csv and initiate objects in the databse.

However, it gives "No such file or directory: ..." error. Putting the file in myapp/static folder causes other problem.

How do I go about this? Is there more clever way to tackle this problem? Thanks so much!


For efficiency, App Engine stores and serves static files separately from application files. Static files are not available in the application's file system. If you have data files that need to be read by the application code, the data files must be application files, and must not be matched by a static file pattern.

Reference here

To access your file, save it in the same directory of your script and access it through something like this:

file_path = os.path.join(os.path.dirname(__file__), 'info.csv')
your_file = open(file_path)


I have also seen and used this design pattern:

in config.py:

INFO: [a,b,c] #or whatever would otherwise go in info.csv

in views.py:

import config

your_data = config.INFO
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜