Flask route to download .xml files leading to 404 Not Found
Question: I have a `flask` (0.10.1) app running on a `Debian Jessie VPS` and powered by
`nginx` (1.6.2). The app is working fine but I have a problem on a specific
`route` I added recently.

The `route` is intended for downloading `.xml` files.

It is dynamic to tell the directory and the file name:

    
    
    @app.route('/backups/<dir_key>/<filename>')
    

And it registers a function based on the `flask` `send_from_directory`
function:

    
    
    def backups(dir_key,filename):
        directory = os.path.join(app.config['BACKUPXML_FOLDER'], dir_key)
        return send_from_directory(directory, filename, as_attachment=True)
    

The route is generated thanks to the `flask` `url_for` function, and returned
to the frontend:

    
    
    return jsonify({
        'backupFileUrl': url_for('backups', dir_key=dir_key, filename = filename, _external=True)
    })
    

where it is stored in an `AngularJS` variable:

    
    
    $scope.backupFileUrl = response.backupFileUrl;
    

And finally included in a `<a>` tag for download :

    
    
    <a class="btn btn-primary"
       ng-show="sessionDownload"
       ng-href="{{ backupFileUrl }}" target="_blank">
       <span class="glyphicon glyphicon-save"></span> Télécharger </a>
    

But when I click on the button, I get the following error :

[![enter image description
here](http://i.stack.imgur.com/SNHYu.png)](http://i.stack.imgur.com/SNHYu.png)

What is weird to is that :

  1. The download is properly triggered when the app is powered by a small `Python` server on a local `Windows` machine.
  2. I have a `route` intended for downloads of `.xlsx` files which is actually working, and both on a local `Windows` machine and on the `Jessie VPS`.

Someone see how I can define the `route` to make it work ?

Here is the api architecture if needed :

**api/app.py**

    
    
    import sys
    sys.path.append('../')
    
    from flask_script import Server, Manager
    from kosapp import app, db
    
    manager = Manager(app)
    
    if __name__ == '__main__':    
        manager.run()
    

**api/config.py**

    
    
    from os.path import abspath, dirname, join
    import tempfile
    
    basedir = dirname(abspath(__file__))
    BASEDIR = dirname(abspath(__file__))
    
    DEBUG = True
    
    REPORTS_FOLDER = '/tmp/reports'
    # on local machine 
    # REPORTS_FOLDER = os.path.join(tempfile.gettempdir(), 'reports') 
    
    BACKUPXML_FOLDER = '/tmp/backups'
    # on local machine
    # BACKUPXML_FOLDER = os.path.join(tempfile.gettempdir(), 'backups')
    

**api/kosapp/__init__.py**

    
    
    from flask import Flask
    
    app = Flask(__name__)
    app.url_map.strict_slashes = False
    app.config.from_object('config')
    
    from kosapp import views
    

**api/kosapp/views.py**

    
    
    import os
    
    from flask import send_file, jsonify, request, render_template, send_from_directory
    
    from kosapp import app
    
    @app.route('/reports/<dir_key>/<filename>')
    def reports(dir_key, filename):
        directory = os.path.join(app.config['REPORTS_FOLDER'], dir_key)
        return send_from_directory(directory, filename)
    
    @app.route('/backups/<dir_key>/<filename>')
    def backups(dir_key,filename):
        directory = os.path.join(app.config['BACKUPXML_FOLDER'], dir_key)
        return send_from_directory(directory, filename, as_attachment=True)
    

As a note, the route `'/reports/<dir_key>/<filename>'` is intended for
downloading `.xlsx` file and works fine.


Answer: Did you remember to reload the app on the server? That's usually the problem
if i get different results on my development computer and the web server.

For instance, if you deployed with `gunicorn`, you would have to restart
`gunicorn` so the server would know about the changes to your code.

