Advertisement
rollovercable

flask view sample

Aug 31st, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. @blueprint.route("/<path_hash>/<filename>")
  2. def static_file(path_hash, filename ):
  3.     article = db.session.query(xx.xxx.xx)
  4.     path_hash_config = URLSafeSerializer('this is secret', salt='pocoo fans')
  5.     # article[1][7] -> returning email
  6.     path_hash = path_hash_config.dumps(article[1][7])
  7.     path_unhash = path_hash_config.loads(path_hash_config.dumps(article[1][7]))
  8.     # article[1][3] -> get file relative path ex: guido@gmail.com/images/writings/sssss.jpg
  9.     #filename variable  to get the filename so "guido@gmail.com/images/writings/a.jpg" returning a.jpg
  10.     filename = article[1][3].split('/')[3]
  11.     file_location = path_unhash + '/' + filename
  12.  
  13.     # return send_from_directory(static_folder, path_unhash)
  14.     # return send_from_directory(static_folder, request.path[1:])
  15.     return send_from_directory(static_folder, file_location)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement