README.rst 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. ===============
  2. django-crequest
  3. ===============
  4. .. contents::
  5. Overview
  6. ========
  7. - ``crequest`` takes care of current ``request`` in silent way.
  8. - ``crequest`` will bring you current ``request`` object of your Django application from anywhere in your code.
  9. Installing
  10. ==========
  11. ``django-crequest`` is available on http://pypi.python.org/pypi/django-crequest
  12. So it can be installed it by pip::
  13. $ python pip install django-crequest
  14. Or you can grab the latest version tarball and ::
  15. $ python setup.py install
  16. To enable ``django-crequest`` in your project
  17. * Add ``crequest`` to *INSTALLED_APPS* in your **settings.py**
  18. * Add ``crequest.middleware.CrequestMiddleware`` to ``MIDDLEWARE_CLASSES`` after the authentication and session middleware.
  19. Supported Python versions
  20. =========================
  21. ``django-crequest`` currently can be run on multiple python versions:
  22. * Python 2
  23. * Python 3
  24. * PyPy
  25. How to use
  26. ==========
  27. First import the crequest's middleware::
  28. from crequest.middleware import CrequestMiddleware
  29. Get the current ``request`` ;)::
  30. current_request = CrequestMiddleware.get_request()
  31. Done.
  32. In depth & Complex details
  33. ==========================
  34. Set the current request in UnKnown situations::
  35. CrequestMiddleware.set_request(request)
  36. Return *iam_request* if there is no current request::
  37. CrequestMiddleware.get_request(iam_request)
  38. And finally delete::
  39. CrequestMiddleware.del_request()
  40. The middleware automatically sets/deletes the current request for HTTP requests.
  41. For other uses (management commands, scripts), you will need to do this yourself.