https://github.com/dldevinc/ssi-views
A simple Django application to process SSI includes
https://github.com/dldevinc/ssi-views
django nginx ssi
Last synced: 5 months ago
JSON representation
A simple Django application to process SSI includes
- Host: GitHub
- URL: https://github.com/dldevinc/ssi-views
- Owner: dldevinc
- License: mit-0
- Created: 2021-02-08T07:20:38.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-12-23T07:26:00.000Z (over 1 year ago)
- Last Synced: 2024-12-23T08:27:13.656Z (over 1 year ago)
- Topics: django, nginx, ssi
- Language: Python
- Homepage:
- Size: 67.4 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# ssi-views
A simple Django application to process SSI includes.
[](https://pypi.org/project/ssi-views/)
[](https://github.com/dldevinc/ssi-views)
[](https://pypi.org/project/ssi-views/)
## Compatibility
- `python` >= 3.9
- `django` >= 3.2
## Features
- Supported Function-Based and Class-Based Views
- One URL pattern ~~to rule them all~~ for all SSI views
- Jinja2 support
## Installation
Install the latest release with pip:
```shell
pip install ssi-views
```
Add `ssi_views` to your INSTALLED_APPS in django's `settings.py`:
```python
INSTALLED_APPS = [
"ssi_views",
]
```
Add `ssi_views.urls` to your URLconf:
```python
from django.urls import include, path
urlpatterns = [
path("ssi/", include("ssi_views.urls")),
]
```
## Usage
#### @ssi_view("name")
Use this decorator to register your views (Function-Based or Class-Based).
```python
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:
```python
@csrf_exempt
@require_POST
@ssi_view("myapp.contact_form")
def csrf_exempt_view(request):
# ...
```
#### {% ssi_include %}
Template tag to render `` directive.
```djangotemplate
{% load ssi_views %}
{% ssi_include "myapp.form" %}
```
Output:
```html
```
#### {% ssi_url %}
This tag is used to add SSI URLs in the template files:
```djangotemplate
{% load ssi_views %}
```
#### Multiple names
You can have multiple names for the same view:
```python
from ssi_views.decorators import ssi_view
@ssi_view(["myapp.form", "myapp.fallback"])
def example_view(request):
...
```
## Jinja2 support
Enable Jinja2 extension
```python
TEMPLATES = [
{
"BACKEND": "django.template.backends.jinja2.Jinja2",
"OPTIONS": {
"extensions": [
...
"ssi_views.templatetags.ssi_views.SSIIncludeExtension",
]
}
}
]
```
**NOTE**: If you are using [django-jinja](https://niwinz.github.io/django-jinja/latest/), you don't need to do this.
The usage is similar to Django, except that `ssi_url` is a global function:
```jinja2
```