I am having trouble using images, html files and javascript with Google App Engine. I have a folder in my application folder called static. In the static folder I have 3 other folders called ‘images’, ‘html’, and ‘javascript’. My handlers part of my app.yaml is as follows,
handlers:
- url: /html
static_dir: static/html
- url: /javascript
static_dir: static/javascript
- url: /images
static_dir: static/images
- url: /.*
script: index.app
I try to access an image with,
self.response.out.write('<img src="images/image.png">')
and I render an html using jinja2 with,
jinja_environment = jinja2.Environment(autoescape=True,
loader=jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__), 'html')))
template = jinja_environment.get_template('index.html')
self.response.out.write(template.render(template_values))
I am getting an error that the template for jinja could not be found and my image is also not found. I thought this was the correct way to use upload and use files with Google App Engine but obviously I am wrong.
What is the proper way that I can use files in folders with Google App Engine?
Using Jinja, you render a template which writes HTML. That is not static serving.
And in your app.yaml you use: static/images or static/html
But in your code you use another path!! Without the static folder.
So if you have a folder static and in that folder you have a folder image:
And your loader: