Metadata-Version: 2.1
Name: django-namespaces
Version: 0.0.7
Home-page: https://github.com/jmitchel3/django-namespaces
Author: Justin Mitchel
Author-email: hello@teamcfe.com
License: MIT
Project-URL: Documentation, https://github.com/jmitchel3/django-namespaces
Project-URL: Changelog, https://github.com/jmitchel3/django-namespaces/blob/main/HISTORY.rst
Project-URL: Twitter, https://twitter.com/joincfe
Keywords: Django
Classifier: Development Status :: 1 - Planning
Classifier: Framework :: Django :: 3.2
Classifier: Framework :: Django :: 4.0
Classifier: Framework :: Django :: 4.1
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Typing :: Typed
Requires-Python: >=3.7
Description-Content-Type: text/markdown

# django-namespaces

Use namespaces in requests using Django.


## Motivation

Google Cloud has an interest feature for namespacing projects. Namespacing can enable assets to be isolated from each other without needing to leverage subdomains and/or multiple databases (although you can use those too).


## Installation

Use a virtual environment whenever using Python packages. The built-in [venv](https://docs.python.org/3/library/venv.html) module is great.
```
python3 -m venv venv
source venv/bin/activate
$(venv) python -m pip install django-namespaces --upgrade
```

## Configure your Django Project

### Create a Django Project
```
$(venv) mkdir -p src && cd src
$(venv) django-admin startproject cfehome .
```

### Installed Apps
Add `django_namespaces` to your `INSTALLED_APPS` in `settings.py`:
```python
INSTALLED_APPS = [
    ...
    'django_namespaces',
]
```

### Update Middelware
Update `MIDDLEWARE` in `settings.py` to include `NamespaceMiddleware`:
```python
MIDDLEWARE = [
    ...
    'django_namespaces.middleware.NamespaceMiddleware',
]
```


This gives us access to the `request.namespace` object in our views.


## Basic Usage

```python
import django_namespaces
django_namespaces.activate("hello-world")
```
This will add a namespace to the request object.

```python

def my_hello_world_view(request):
    print(request.namespace) # <Namespace: hello-world>
    print(request.namespace.value) # hello-world
    return HttpResponse("Hello World") 
```


### Optional Views
Using views are optional. You can also use the `activate` function to activate a namespace.

#### Update URLconf
Update `urls.py` to include `namespaces.urls`:
```python
urlpatterns = [
    ...
    path('namespaces/', include('django_namespaces.urls')),
]
```


#### Create a Namespace
Create a namespace by visiting `http://localhost:8000/namespaces/create/` and filling out the form.


#### Activate a Namespace
Activate a namespace by visiting `http://localhost:8000/namespaces/` and hitting `activate` on your newly created namespace.

You can also use:


#### Update URLconf


