Dai Wei
Dai Wei

Reputation: 21

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 initiated 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!

Upvotes: 2

Views: 581

Answers (2)

DanDan
DanDan

Reputation: 101

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

Upvotes: 0

systempuntoout
systempuntoout

Reputation: 74104

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)

Upvotes: 4

Related Questions