Static files in Flask - robot.txt, sitemap.xml (mod_wsgi)

前端 未结 10 604
后悔当初
后悔当初 2020-11-29 15:15

Is there any clever solution to store static files in Flask\'s application root directory. robots.txt and sitemap.xml are expected to be found in /, so my idea was to create

10条回答
  •  猫巷女王i
    2020-11-29 16:07

    This might have been added since this question was asked, but I was looking through flask's "helpers.py" and I found flask.send_from_directory:

    send_from_directory(directory, filename, **options)
    '''
      send_from_directory(directory, filename, **options)
      Send a file from a given directory with send_file.  This
      is a secure way to quickly expose static files from an upload folder
      or something similar.
    '''
    

    ... which references flask.send_file:

    send_file(filename_or_fp, mimetype=None, as_attachment=False, attachment_filename=None, add_etags=True, cache_timeout=43200, conditional=False)
    

    ... which seems better for more control, although send_from_directory passes **options directly through to send_file.

提交回复
热议问题