I'm using app engine and I don't know how to read a static file from my project. I have a file structure that globally looks like this:
- html (static folder)
- staticfile1.html
- staticfile2.html
- script
- main.py
app.yaml
In my app.yaml I already set the application_readably attribute to true for the html dir:
- url: /html
static_dir: html
application_readable: true
I tried several methods to access the staticfile1.html but either of them returns this error:
[Errno 13] file not accessible: u'/html/staticfile1.html'
At the moment my code looks like this:
INDEX_HTML = open('/html'+self.request.path).read()
self.response.out.write(INDEX_HTML)
I hope someone knows how I can read the static file. Thanks in advance.
答案 0 :(得分:1)
You'll probably need to use relative paths based on the current module's __file__
attribute. e.g. from main.py
, you'd do something like:
import os
_HERE = os.path.basename(__file__)
_HTML_DIR = os.path.join(_HERE, os.pardir, 'html')