sample code to explain the custom middleware and ip blocking
This is the sample code used to explain this article - http://thepythondjango.com/develop-reusable-distributable-django-app-block-crawling-ip-addresses/
To view the source code of actual reusable app, please visit - https://github.com/anuragrana/django-bot-crawler-blocker
This package is available on pypi - https://pypi.python.org/pypi/django-bot-crawler-blocker