Server Tag Django Package
A Django package to fetch and render scripts from a remote URL with template tag integration and caching support.
Installation
Install the package via pip:
pip install adunblock-server-tag-django
Add the server_tag app to your INSTALLED_APPS in your Django settings.py:
INSTALLED_APPS = [
# ... other apps
'server_tag',
]
Configure caching in your settings.py (recommended for production):
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
'LOCATION': 'redis://127.0.0.1:6379/1',
}
}
# Or for development, use local memory cache:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'unique-snowflake',
}
}
Usage
In your Django template, load the server_tag_tags and use the server_tag tag:
{% load server_tag_tags %}
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
{% server_tag "https://your-remote-url.com/scripts" %}
</head>
<body>
<h1>My Page</h1>
</body>
</html>
Custom Script Attributes
Pass a script_attributes dict from your view context to render extra attributes (including data-*) on the generated <script> tag:
# views.py
def my_view(request):
return render(request, 'my_template.html', {
'script_attrs': {
'data-code': 'abc123',
'data-source': 'server-tag',
'defer': True,
},
})
{% load server_tag_tags %}
{% server_tag "https://your-remote-url.com/scripts" script_attributes=script_attrs %}
Rendering rules:
True→ bare attribute (e.g.defer)False/None→ omitted- any other value →
key="value"(HTML-escaped)
By default, every rendered script includes async. Set script_attributes={'async': False} to disable it.
The tag it prints
By default the package prints one tag, for the first URL in the response (the preferred one):
<script data-cfasync="false" nowprocket src="SCRIPT_URL" async data-code="ACCOUNT_ID"></script>
data-cfasync="false"andnowprocketcome beforesrc: Cloudflare Rocket Loader skips a script only whendata-cfasync="false"precedessrc, andnowprocketkeeps WP Rocket's Delay JavaScript Execution off it. Pass either withfalseto drop it.- Your attributes (
data-codeand anything else) come aftersrc. - Only the first URL is rendered: the client must load once per page, since each copy runs its own adblock detection and asks for its own proxy session. A custom renderer still receives every URL.
The site's domain
The tag sends your site's domain to the sources endpoint as ?domain=, taken from request.get_host() when the template context has the request (the django.template.context_processors.request context processor, on in new projects), or from a domain argument: {% server_tag "https://public.adunblocker.com/api/vendor_scripts" domain="example.com" %}. A host outside ALLOWED_HOSTS sends no domain. When an ad blocker rule targets one site, we publish a new script host for that site alone, and only a request naming the site receives it. A domain parameter already in your URL is kept as it is.
Custom Rendering
You can provide a custom Python function to the render_script parameter to customize how script tags are rendered:
# my_app/templatetags/custom_tags.py
from django import template
from django.utils.safestring import mark_safe
register = template.Library()
@register.simple_tag
def custom_script_renderer(js_files):
from django.utils.html import escape
scripts = [f'<script src="{escape(src)}" defer></script>' for src in js_files.get('js', [])]
return mark_safe('\n'.join(scripts))
{% load server_tag_tags %}
{% load custom_tags %}
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
{% server_tag "https://your-remote-url.com/scripts" render_script=custom_script_renderer %}
</head>
<body>
<h1>My Page</h1>
</body>
</html>
Features
- Template Tag Integration: Easy-to-use Django template tag
- HTTP Client: Uses requests library for reliable HTTP operations
- Caching: Built-in Django cache integration with configurable TTL
- Error Handling: Graceful error handling with fallback to empty arrays
- Security: XSS protection with proper HTML escaping
- Django Integration: Proper Django app structure with apps.py
Requirements
- Python 3.8 or higher
- Django 3.2 or higher
- requests 2.25.0 or higher
Metadata
Release files for adunblock-server-tag-django 1.2.0
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 |
|---|---|---|---|---|
| adunblock_server_tag_django-1.2.0.tar.gz | 7.1 kB | Without provenance | Details for adunblock_server_tag_django-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| adunblock_server_tag_django-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for adunblock_server_tag_django-1.2.0-py3-none-any.whl |
Total release size: 13.4 kB
Release files / adunblock_server_tag_django-1.2.0.tar.gz
| Download URL | adunblock_server_tag_django-1.2.0.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0043b899287d30a025cd8b69aceec0edd64e7ed9b1a35df65c0ae8b5196d335b
|
|
BLAKE2b-256 checksum How to use checksums |
58e06a790b64a6b93d1073ddf6dbbdd85efad315935d76aa735340a3989e28f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.8
|
Release files / adunblock_server_tag_django-1.2.0-py3-none-any.whl
| Download URL | adunblock_server_tag_django-1.2.0-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
93bfb8d84460fba16cdf66f7a05d416cf2299488404a2860925c3519db35a7cd
|
|
BLAKE2b-256 checksum How to use checksums |
f595c6b574efd2236883e6644e1a47282af53b82d73f53dd4bdef7c0ae9bd4e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.8
|
Security for adunblock-server-tag-django 1.2.0
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.