Some of us may believe that checking every time whether a request is XHR kills code readability. To solve this, we have an easy solution. In this recipe, we will write a simple decorator that can handle this redundant code for us.
Using decorators to handle requests beautifully
Getting ready
In this recipe, we will be writing a decorator. For some Python beginners, this might seem like alien territory. In this case, read http://legacy.python.org/dev/peps/pep-0318/ for a better understanding of decorators.
How to do it...
The following is the decorator method that we have...