Advertisement
kopyl

Untitled

Mar 12th, 2021
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1.  
  2. from flask_cors import cross_origin
  3. from flask import (
  4.     Flask,
  5.     request,
  6.     abort,
  7.     render_template,
  8. )
  9. from waitress import serve
  10. from word_scraper import Word
  11.  
  12.  
  13. app = Flask(
  14.     __name__,
  15.     template_folder='build',
  16.     static_folder='build'
  17. )
  18.  
  19.  
  20. @app.route('/', strict_slashes=False)
  21. def main_page() -> str:
  22.     html_page = render_template('index.html')
  23.     return html_page
  24.  
  25.  
  26. @app.route(f"/api/<word>")
  27. @cross_origin()
  28. def index(word):
  29.     word_to_give = Word(word).get_raw(
  30.         no_mongo_id=True,
  31.         schema="API"
  32.     )
  33.     if word_to_give == None:
  34.         word_to_give = {}
  35.     return word_to_give
  36.  
  37.  
  38. if __name__ == '__main__':
  39.     serve(app, port=80, host='cdict.ru')
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement