Skip to main content

Middleware to make current request always available.

Project description

django-crequest - Take care of current request in silent way.

Copyright (C) 2012 Alireza Savand <alireza.savand@gmail.com>

Overview

crequest will bring you current request object of your django application from anywhere in your code.

Installing

django-crequest is available at http://pypi.python.org/pypi/django-crequest So it can be installed by pip:

$ pyhton pip install django-crequest

Or you can grab the latest version tarball and

$ python setup.py install

To enable django-crequest in your project

  • Add ‘crequest’ to INSTALLED_APPS in your settings.py

  • Add ‘crequest.middleware.CrequestMiddleware’ to MIDDLEWARE_CLASSES after the authentication and session middleware.

How to use it

First import the crequest’s middleware:

from crequest.middleware import CrequestMiddleware

Get the current request ;):

current_request = CrequestMiddleware.get_request()

Done.

Some info for some folks

Set the current request in UnKnown situations:

CrequestMiddleware.set_request(request)

Return iam_request if there is no current request:

CrequestMiddleware.get_request(iam_request)

And finally delete:

CrequestMiddleware.del_request()
The middleware automatically sets/deletes the current request for HTTP requests.

For other uses (management commands, scripts), you will need to do this yourself.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-crequest-1.0.tar.gz (3.4 kB view details)

Uploaded Source

File details

Details for the file django-crequest-1.0.tar.gz.

File metadata

File hashes

Hashes for django-crequest-1.0.tar.gz
Algorithm Hash digest
SHA256 c80f30676f5dd432e9fc5abbf2f08af9c38ba080994f3eac61eef003ee51513f
MD5 0830cc48dfa63593fa7c3e23a6b5ea62
BLAKE2b-256 e71202fca73b3b66972fe49b64b4c23587b283edc7d15b9aa6751e6f309fd515

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page