-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifications.py
More file actions
42 lines (32 loc) · 1.22 KB
/
notifications.py
File metadata and controls
42 lines (32 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
from __future__ import print_function
"""
Custom event notifications
~~~~~~~~~~~~~~~~~~~~~~~~~~
Flask supports callback functions via decorators such as
`before_request` and `after_request`. Being a subclass of Flask, Eve
supports this mechanism too, and it's pretty darn powerful. The catch is
that you need to be quite familiar with Flask internals, so for example if
you want to inspect the `request` object you have to explicitly import it
from flask.
Checkout Eve at https://github.com/nicolaiarocci/eve
This snippet by Nicola Iarocci can be used freely for anything you like.
Consider it public domain.
"""
from flask import request
from eve import Eve
from notifications_settings import SETTINGS
app = Eve(auth=None, settings=SETTINGS)
@app.before_request
def before():
print('the request object ready to be processed:', request)
@app.after_request
def after(response):
"""
Your function must take one parameter, a `response_class` object and return
a new response object or the same (see Flask documentation).
"""
print('and here we have the response object instead:', response)
return response
if __name__ == '__main__':
app.run()