Namespace resolution context processor
Django supports namespaces that help applications find out their current namespace and refer to themselves in a stable way even if there are more than one instance of the same module in the url patterns.
However, Django does not automatically set the current_app context which means that the app will actually resolve the namespaced urls to the last announced instance of itself.
This context processor digs the detail up and voilá.
Usage
The context processor needs to be added to the template configuration. The rude way to do it is as follows:
TEMPLATES[0]['OPTIONS']['context_processors'].append(
'namespaced.context_processors.namespaced')
Using a context processor for this use is a bit questionable and generally a middleware would be the correct place to edit requests. However middlewares are executed at a stage where the URL resolution has not been matched and will traverse all URLs even if they are not going to be used. This code is mostly relevant in views anyway.
This enables you to have two separate instances of the same app in two different urls. Normally Django would always refer to the last instance by the app name which will mess up all internal linkage within any of the previous instances. Let’s assume we have this inside an app:
{% url 'myapp:index' %}
To make this work for both instances, the urls.py should look something like this:
urlpatterns = [
url(r'^first/', include('myapp.urls', namespace='first', app_name='myapp')),
url(r'^last/', include('myapp.urls', namespace='last', app_name='myapp)),
]
The apps can refer to themselves with myapp:, each other with first: and last:. It will most likely make sense to use the explicit names in the rest of the project.
For now, the use without namespaces has not been tested.
Metadata
Release files for django-namespaced 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-namespaced-1.0.1.tar.gz | 18.3 kB | Without provenance | Details for django-namespaced-1.0.1.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_namespaced-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for django_namespaced-1.0.1-py3-none-any.whl |
| django_namespaced-1.0.1-py2-none-any.whl | Python 2 | none | any | Details for django_namespaced-1.0.1-py2-none-any.whl |
Total release size: 36.8 kB
Release files / django-namespaced-1.0.1.tar.gz
| Download URL | django-namespaced-1.0.1.tar.gz |
|---|---|
| Size | 18.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c9dc3e035fead5bd97fb251f4a6f7c812abeff14d58b31cc202db8772848d611
|
|
BLAKE2b-256 checksum How to use checksums |
c27b899544cd8aea99791a60bcaeaa00159b9a04185454d3a09a22de2577dd50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / django_namespaced-1.0.1-py3-none-any.whl
| Download URL | django_namespaced-1.0.1-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6505100b1ed62d55d140d811b7f7545b5c4dc7061525d60832d6404a6a41db81
|
|
BLAKE2b-256 checksum How to use checksums |
02d3e6765d643911137626f83d0e1bbc62b94b94295cea04f544871ce7509acc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / django_namespaced-1.0.1-py2-none-any.whl
| Download URL | django_namespaced-1.0.1-py2-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
f89850286d911fff5f1edf9076451d873a77eca893173368fe0ccbd87dc1662b
|
|
BLAKE2b-256 checksum How to use checksums |
fdf71b691e883025441f10881771b27a7d4dd4d5037399e2d5bb1f79627b2d09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-namespaced 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.