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

前端 未结 10 603
后悔当初
后悔当初 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条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 16:08

    From the documentation here: http://flask.pocoo.org/docs/quickstart/#static-files

    Dynamic web applications need static files as well. That’s usually where the CSS and JavaScript files are coming from. Ideally your web server is configured to serve them for you, but during development Flask can do that as well. Just create a folder called static in your package or next to your module and it will be available at /static on the application.

    To generate URLs to that part of the URL, use the special 'static' URL name:

    url_for('static', filename='style.css')

    The file has to be stored on the filesystem as static/style.css.

提交回复
热议问题