django-dynamic-resource-admin
Add dynamic css & js resources to django's admin site.
Install
pip install django-dynamic-resource-admin
Usage
Note:
-
We use template override mechanism, so you MUST add app name django_dynamic_resource_admin into INSTALLED_APPS.
-
The parameter request pass to get_css&get_js is the request of this view.
-
The parameters **kwargs pass to get_css&get_js are the paramters of admin view prameters.
-
Every extra js part is wrappered with closure function, so that they will be NO local variables conflict. If you want to add a global variable, name it like:
window.xxx = 123;.;(function(){ ...your js code... })();
pro/settings.py
INSTALLED_APPS = [
...
'django_dynamic_resource_admin',
...
]
app/admin.py
from django.contrib import admin
from django_dynamic_resource_admin.admin import DjangoDynamicResourceAdmin
from .models import Book
class BookAdmin(DjangoDynamicResourceAdmin, admin.ModelAdmin):
def get_css(self, request, **kwargs):
csses = super().get_css(request)
csses += [
"""
body{
background-color: red;
}
""",
]
return csses
admin.site.register(Book, BookAdmin)
How to add your custom css&js?
- Override get_css to add extra css.
- Override get_js to add extra js.
def get_css(self, request, **kwargs):
extra_css = super().get_css(request, **kwargs)
extra_css += [
"""body{xxx}""",
""".title{xxx}"""
]
return extra_css
def get_js(self, request, **kwargs):
extra_js = super().get_js(request, **kwargs):
extra_js += [
"""window.msg="hello world";""",
"""...""",
]
return extra_js
Release
v0.1.1 2020/09/25
- Fix js code wrapper from
<style></style>to<script type="text/javascript"></script>. - Add license file.
v0.1.0 2020/03/13
- First realse.
Metadata
Release files for django-dynamic-resource-admin 0.1.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-dynamic-resource-admin-0.1.1.tar.gz | 3.9 kB | Without provenance | Details for django-dynamic-resource-admin-0.1.1.tar.gz |
Release files / django-dynamic-resource-admin-0.1.1.tar.gz
| Download URL | django-dynamic-resource-admin-0.1.1.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d3ce6eed41bc1c1faa14cb1d4dd204c903f8a196b9f1f8beb578d56d62d69c1e
|
|
BLAKE2b-256 checksum How to use checksums |
620e6c38d210bdd4de5860aad3d01a0d5c8c6fbb3cffee3642151892d41cba35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.6.8
|
Security for django-dynamic-resource-admin 0.1.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.