1

I am not sure atm. where to put files like .htaccess or robots.txt.

And I am struggling to find the correct and up to date answer, because there are many similar questions.

I have my flask app and 2 folders static und templates.

In templates I have all my html files and thats it.

In static I have css js static images. But where do I put files like .htaccess or robots.txt.

For example the requirements.txt is with all the py files. Version 1:

enter image description here

Or do I have to move these files to static?:

enter image description here

EDIT:

This has nothing to do with robots itself... I know where robots has to be. I need to understand how flask serves these files. As far as I know flask uses the static folder as root, but still procfile and requirements have to be with the py files.

Roman
  • 3,563
  • 5
  • 48
  • 104
  • Possible duplicate of [Where to put robots.txt file?](http://stackoverflow.com/questions/2984607/where-to-put-robots-txt-file) – maiky_forrester Mar 27 '17 at 06:50
  • 1
    This has nothing to do with robots itself... I know where robots has to be. I need to understand how flask serves these files. As far as I know flask uses the static folder as root, but still procfile and requirements have to be with the py files. – Roman Mar 27 '17 at 06:59

2 Answers2

3

Okay I managed to find a working solution here: Answer from @bebbi

It is indeed not the way to go to put files like robots.txt in the folder with the py files.

The files are simply moved to the static folder of your flask app and served like this:

@app.route('/robots.txt')
@app.route('/sitemap.xml')
def static_from_root():
    return send_from_directory(app.static_folder, request.path[1:])
Community
  • 1
  • 1
Roman
  • 3,563
  • 5
  • 48
  • 104
0

You need to move them to static, whose directory structure directly mirrors how URLs will be built to access those static assets (unless you specifically configure it to be otherwise).

The bigger issue is that, while it's convenient for development purposes for Flask to serve static files, it's not recommended in production (and that comes directly from the Flask docs).

jeffknupp
  • 5,966
  • 3
  • 28
  • 29