2
votes

I have a router

@app.route('/images/<filename>')
def images(filename):
    send from(os.path.join('uploads', filename))

My images are saved in some directory called 'uploads'. And I configure nginx to serve static files.

My question is when I use url_for('images', filename='1.jpg') in jinja template, which should generate something like src="/images/1.jpg" in browser, if the user click this link, will nginx serve the file or flask serve it?

Another example: when using url_for('static', filename='style.css') in template, is nginx serving it?

1
It entirely depends on how you have nginx configured. - Sean Vieira

1 Answers

0
votes

The solution shall work well, if follows these rules:

  • you know exactly what static files you are going to be served
  • your jinja based templates are generating proper links to these files
  • ngingx is properly configured to serve these static files

Under these (production) conditions, your Python code shall not get requests to these static files as they are served by nginx.

This is desired behaviour, as it off-loads python application by nginx, which can serve those files much more efficiently.