title: How to use decorators to validate request and proceed else throw error
body: <p>I wanted to know how can I use decorator to validate JSON request in django. Currently I have <code>validations.py</code> file with the function <code>validate</code> which returns <code>True</code> if request is valid else returns <code>False</code>. </p>
  
  <p>My current implementation is like:</p>
  
  <p>validations.py:</p>
  
  <pre><code>def validate(request):
     flag = True
     .... # Actual logic for validating request and 
          # sets flag to True/False
     return flag
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>from validations import validate
  
  def authenticate_user(request):
       if validate(request):
          .......
          # executes further logic based on request
          # This checks if right access is present in Database
          # for the user or not. And hence I want to access request variable as it is
       else:
          return "Bad Request"
  </code></pre>
  
  <p>I wanted to know how exactly I can use decorator here and do something like this:</p>
  
  <pre><code>@validate
  def authenticate_user(request):
      .......
      # executes further logic based on request
      # This checks if right access is present in Database
      # for the user or not. And hence I want to access request variable as it is
  </code></pre>
  
  <p><code>validate</code> function should directly return <code>"Bad Request"</code> to the client if validations fails for any reason else normal code execution should happen.</p>