django-g


Namedjango-g JSON
Version 0.0.2 PyPI version JSON
download
home_pagehttps://github.com/buserbrasil/django-g
SummaryDjango global context
upload_time2022-12-26 14:18:26
maintainer
docs_urlNone
authorIuri de Silvio
requires_python
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # django-g

Django global context to get current request from anywhere in your application.

Many scenarios need the current request but Django don't have it accessible.
They expect that your application implement a middleware to use the request,
but it is burdensome and not reusable.

Other packages, like [django-threadlocals](https://pypi.org/project/django-threadlocals/) do the same thing with threadlocals, but it doesn't work on the
async world.

## How to install

```
$ pip install django-g
```

## How to use

Add `django_g.middleware.RequestMiddleware` to your settings `MIDDLEWARE`. It
is a small middleware just to capture the current request and save to global
context, ordering probably doesn't matter because any other middleware
already have access to the request.

```python
MIDDLEWARE = [
    "django_g.middleware.RequestMiddleware",
    ...
]
```


```python
from django_g import get_current_request


def your_func():
    request = get_current_request()
    # Use the request here. Be careful and handle when `request=None`.
```

**protip** It is not a good idea to get the request everywhere, because you're
coupling the framework specifics with your logic, so use this package only to
get the request where you don't have a better way.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/buserbrasil/django-g",
    "name": "django-g",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Iuri de Silvio",
    "author_email": "iurisilvio@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/5b/8b/fb5f3d59f218198f679c81ed18fa6440cfb2b6faa313521b6604c1447f03/django-g-0.0.2.tar.gz",
    "platform": null,
    "description": "# django-g\n\nDjango global context to get current request from anywhere in your application.\n\nMany scenarios need the current request but Django don't have it accessible.\nThey expect that your application implement a middleware to use the request,\nbut it is burdensome and not reusable.\n\nOther packages, like [django-threadlocals](https://pypi.org/project/django-threadlocals/) do the same thing with threadlocals, but it doesn't work on the\nasync world.\n\n## How to install\n\n```\n$ pip install django-g\n```\n\n## How to use\n\nAdd `django_g.middleware.RequestMiddleware` to your settings `MIDDLEWARE`. It\nis a small middleware just to capture the current request and save to global\ncontext, ordering probably doesn't matter because any other middleware\nalready have access to the request.\n\n```python\nMIDDLEWARE = [\n    \"django_g.middleware.RequestMiddleware\",\n    ...\n]\n```\n\n\n```python\nfrom django_g import get_current_request\n\n\ndef your_func():\n    request = get_current_request()\n    # Use the request here. Be careful and handle when `request=None`.\n```\n\n**protip** It is not a good idea to get the request everywhere, because you're\ncoupling the framework specifics with your logic, so use this package only to\nget the request where you don't have a better way.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Django global context",
    "version": "0.0.2",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "398720aabcd69eb9bf4f3e2ff2bc12bc",
                "sha256": "c7c10f5cfcdb321c34f8b3e144759d6536c8eb16144d57b179b96191e5c94c0e"
            },
            "downloads": -1,
            "filename": "django_g-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "398720aabcd69eb9bf4f3e2ff2bc12bc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 3961,
            "upload_time": "2022-12-26T14:18:24",
            "upload_time_iso_8601": "2022-12-26T14:18:24.880651Z",
            "url": "https://files.pythonhosted.org/packages/0f/ca/2d6742407598d098f1adbaa3e55e961a0c6f3f3c9efa3df1db77256befee/django_g-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "f4d2234d63dbc7f058876b7072cf80da",
                "sha256": "3eb6e33a95849e4159c211e792ae2801f909660737eca4551360ac2bc7a65366"
            },
            "downloads": -1,
            "filename": "django-g-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "f4d2234d63dbc7f058876b7072cf80da",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3389,
            "upload_time": "2022-12-26T14:18:26",
            "upload_time_iso_8601": "2022-12-26T14:18:26.040504Z",
            "url": "https://files.pythonhosted.org/packages/5b/8b/fb5f3d59f218198f679c81ed18fa6440cfb2b6faa313521b6604c1447f03/django-g-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-26 14:18:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "buserbrasil",
    "github_project": "django-g",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "django-g"
}
        
Elapsed time: 0.07044s