main
Estelle Poulin 2 years ago
parent 69ad08bd00
commit b845aa6c19

@ -20,19 +20,19 @@ pip install domainate
```python ```python
INSTALLED_APPS = [ INSTALLED_APPS = [
..., ...,
"subjugate", "subjugate",
... ...
] ]
TEMPLATES = [ TEMPLATES = [
..., ...,
{ {
"BACKEND": "subjugate.template.backends.subjugate.SubjugateTemplates", "BACKEND": "subjugate.template.backends.subjugate.SubjugateTemplates",
"DIRS": [], "DIRS": [],
"APP_DIRS": True, "APP_DIRS": True,
"OPTIONS": {"debug": False}, "OPTIONS": {"debug": False},
} }
] ]
``` ```
@ -45,7 +45,7 @@ from subjugate import SubjugateTemplate
from dominate import tags as t from dominate import tags as t
class PageTemplate(SubjugateTemplate): class PageTemplate(SubjugateTemplate):
def render(self, title="Page", description="Cool stuff here", **kwargs): def render(self, title="Page", description="Cool stuff here", **kwargs):
document = dominate.document(title=title) document = dominate.document(title=title)
abs_url = self.request.build_absolute_uri() abs_url = self.request.build_absolute_uri()
@ -70,18 +70,18 @@ class PageTemplate(SubjugateTemplate):
t.meta(property="og:type", content="website") t.meta(property="og:type", content="website")
t.meta(property="og:url", content=f"{abs_url}") t.meta(property="og:url", content=f"{abs_url}")
with document: with document:
t.p("Hello World!") t.p("Hello World!")
return document return document
``` ```
Then in `urls.py` Then in `urls.py`
```python ```python
urlpatterns = [ urlpatterns = [
..., ...,
path("page/", TemplateView.as_view(template_name="yourapp/page.py")), path("page/", TemplateView.as_view(template_name="yourapp/page.py")),
] ]
``` ```
@ -89,52 +89,52 @@ urlpatterns = [
```python ```python
class BaseTemplate(SubjugateTemplate): class BaseTemplate(SubjugateTemplate):
def render(self, title="Blah", **kwargs): def render(self, title="Blah", **kwargs):
document = dominate.document(title=title) document = dominate.document(title=title)
with document.head: with document.head:
t.title(title) t.title(title)
return document return document
class DerivedTemplate(SubjugateTemplate): class DerivedTemplate(SubjugateTemplate):
def render(self, **kwargs): def render(self, **kwargs):
base = self.extend("yourapp/base.py", title="Title Works") base = self.extend("yourapp/base.py", title="Title Works")
with base: with base:
t.p("Hello from the derived template!") t.p("Hello from the derived template!")
return base return base
``` ```
## Other Features ## Other Features
```python ```python
class TemplateVars(SubjugateTemplate): class TemplateVars(SubjugateTemplate):
def render(self, **kwargs): def render(self, **kwargs):
base = self.extend("yourapp/base.py", title="Title Works") base = self.extend("yourapp/base.py", title="Title Works")
with base: with base:
# Context Vars # Context Vars
t.p(self.vars.message) t.p(self.vars.message)
# Page URLs # Page URLs
t.p(self.url('yourapp/copyright.py')) t.p(self.url('yourapp/copyright.py'))
# Static URLs # Static URLs
t.p(self.static('yourapp/humans.txt')) t.p(self.static('yourapp/humans.txt'))
# CSRF Tokens # CSRF Tokens
t.p(self.csrf_token()) t.p(self.csrf_token())
# Filters # Filters
t.p(self.filter("upper", "yes")) t.p(self.filter("upper", "yes"))
# Lorem Ipsum # Lorem Ipsum
t.p(self.lorem_words(count=15)) t.p(self.lorem_words(count=15))
t.p(self.lorem_paragraphs(count=3)) t.p(self.lorem_paragraphs(count=3))
return base return base
``` ```
## But I don't want to use Domainate ## But I don't want to use Domainate

Loading…
Cancel
Save