A simple Django application to process SSI includes.
python
>= 3.9django
>= 3.2
- Supported Function-Based and Class-Based Views
- One URL pattern
to rule them allfor all SSI views - Jinja2 support
Install the latest release with pip:
pip install ssi-views
Add ssi_views
to your INSTALLED_APPS in django's settings.py
:
INSTALLED_APPS = [
"ssi_views",
]
Add ssi_views.urls
to your URLconf:
from django.urls import include, path
urlpatterns = [
path("ssi/", include("ssi_views.urls")),
]
Use this decorator to register your views (Function-Based or Class-Based).
from ssi_views.decorators import ssi_view
@ssi_view("myapp.form")
def form_view(request):
...
@ssi_view("myapp.form_cbv")
class SSIFormView(FormView):
...
NOTE: The specified name has to be unique.
You can combine ssi_view
with other decorators:
@csrf_exempt
@require_POST
@ssi_view("myapp.contact_form")
def csrf_exempt_view(request):
# ...
Template tag to render <!--# include virtual="..." -->
directive.
{% load ssi_views %}
{% ssi_include "myapp.form" %}
Output:
<!--# include virtual="/ssi/myapp.form/" -->
This tag is used to add SSI URLs in the template files:
{% load ssi_views %}
<!--# include virtual="{% ssi_url 'myapp.form' %}" -->
You can have multiple names for the same view:
from ssi_views.decorators import ssi_view
@ssi_view(["myapp.form", "myapp.fallback"])
def example_view(request):
...
Enable Jinja2 extension
TEMPLATES = [
{
"BACKEND": "django.template.backends.jinja2.Jinja2",
"OPTIONS": {
"extensions": [
...
"ssi_views.templatetags.ssi_views.SSIIncludeExtension",
]
}
}
]
NOTE: If you are using django-jinja, you don't need to do this.
The usage is similar to Django, except that ssi_url
is a global function:
<!--# include virtual="{{ ssi_url('myapp.form') }}" -->