Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. from bottle import route, run, template, static_file, request, response, url, default_app, get, post, FileUpload
  2. import bottle
  3. import os
  4. # Aufrufen der Hauptseite
  5. @route('/')
  6. def index():
  7. return template('main_template')
  8. # Einbinden unterschiedlicher Dateien z.B. Bilder oder CSS-Files
  9. @route('/static/style/<filepath:re:.*.css>')
  10. def server_static(filepath):
  11. return static_file(filepath, root='static/style')
  12.  
  13.  
  14. @route('/static/images/<filepath:re:.*.(jpg|png|gif|ico|svg)>')
  15. def img(filepath):
  16. return static_file(filepath, root="static/images")
  17.  
  18. @route('/static/sonstige-bilder/<filepath:re:.*.(jpg|png|gif|ico|svg)>')
  19. def img(filepath):
  20. return static_file(filepath, root='static/sonstige-bilder')
  21. # Formularabfrage
  22. @route('/repeat', method='POST')
  23. def do_login():
  24. username = request.forms.get('username')
  25. password = request.forms.get('password')
  26. if username == 'arsenij' and password == '1234':
  27. return "<p>Your login information was correct.</p>"
  28. else:
  29. return "<p>Login failed.</p>"
  30.  
  31. @route('/upload', method='POST')
  32. def do_upload():
  33. category = request.forms.get('category')
  34. upload = request.files.get('upload')
  35. name, ext = os.path.splitext(upload.filename)
  36. if ext not in ('.fastq'):
  37. return 'File extension not allowed.'
  38.  
  39. save_path = '/tmp/(category)'
  40. if not os.path.exists(save_path):
  41. os.makedirs(save_path)
  42.  
  43. file_path = "{path}/{file}".format(path=save_path, file=upload.filename)
  44. upload.save(file_path)
  45. print(request.files.get('upload'))
  46. return 'File uploaded'
  47.  
  48. if __name__ == '__main__':
  49. bottle.debug(True)
  50. bottle.run(host='0.0.0.0', port=8080, reloader=True)
  51.  
  52. <form action="/upload" method="post" enctype="multipart/form-data">
  53. Category: <input type="text" name="category" />
  54. Select a file: <input type="file" name="upload" />
  55. <input type="submit" value="Start upload" />
  56. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement