Skip to content

Instantly share code, notes, and snippets.

@CykuTW
Last active January 20, 2018 09:42
Show Gist options
  • Save CykuTW/b68dfd71fc08d56df008f76baf8b0fd3 to your computer and use it in GitHub Desktop.
Save CykuTW/b68dfd71fc08d56df008f76baf8b0fd3 to your computer and use it in GitHub Desktop.

Revisions

  1. CykuTW revised this gist Jan 20, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions flask_teapot.py
    Original file line number Diff line number Diff line change
    @@ -10,8 +10,10 @@ class Teapot(MethodView):
    def brew(self):
    abort(418)


    app.add_url_rule('/', view_func=Teapot.as_view(Teapot.__name__))


    if __name__ == '__main__':
    """
    example:
  2. CykuTW renamed this gist Jan 20, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. CykuTW revised this gist Jan 20, 2018. No changes.
  4. CykuTW created this gist Jan 20, 2018.
    25 changes: 25 additions & 0 deletions app.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    from flask import Flask, abort
    from flask.views import MethodView


    app = Flask(__name__)

    class Teapot(MethodView):
    methods = ['BREW']

    def brew(self):
    abort(418)

    app.add_url_rule('/', view_func=Teapot.as_view(Teapot.__name__))

    if __name__ == '__main__':
    """
    example:
    > curl -X BREW 'http://127.0.0.1:5000/'
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
    <title>418 I'm a teapot</title>
    <h1>I'm a teapot</h1>
    <p>This server is a teapot, not a coffee machine</p>
    """
    app.run()