Skip to content

Instantly share code, notes, and snippets.

@untitaker
Created September 5, 2014 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save untitaker/53d34b624910d19da92f to your computer and use it in GitHub Desktop.
Save untitaker/53d34b624910d19da92f to your computer and use it in GitHub Desktop.
import flask
app = flask.Flask('testapp')
@app.route('/dir')
def from_dir():
return flask.send_from_directory('data', 'file.txt')
@app.route('/file')
def from_file():
return flask.send_file('data/file.txt')
.
testapp
data
file.txt
__init__.py
runserver.py
from testapp import app
app.run()
@baisk
Copy link

baisk commented Sep 9, 2014

Hey, I check the example, and I am pretty sure the http://127.0.0.1/dir will occur a 404 not found error in my computer. here is the error code: "if not os.path.isfile(filename):" in send_from_directory.

mac osx, Python 2.7.5 :: Anaconda 1.8.0 (x86_64).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment