from flask import Flask, request, abort, url_for, redirect app = Flask(__name__) # this is called by the if __name__ thing at the bottom of the file. def main(): # debug = True will turn on the debugger and auto-reloading. app.run(debug = True) @app.route("/") def default(): # it's just... page. it page. return PAGE # we can add more fake files to this dict. RESOURCES = { 'text.txt': 'this is the text.txt file!', 'cookie.bear': '🍪🐻', } # this is the route used by the XMLHttpRequest below. @app.route("/") def get_resource(resource): resp = RESOURCES.get(resource) if resp is None: abort(404) return resp PAGE = """ AJAX example
API

""" if __name__ == "__main__": main()