How to use the klein.Plating.CONTENT function in klein

To help you get started, we’ve selected a few klein examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github twisted / klein / docs / introduction / codeexamples / forms.py View on Github external
from klein.storage.memory import MemorySessionStore

app = Klein()

sessions = MemorySessionStore()

requirer = Requirer()

@requirer.prerequisite([ISession])
def procurer(request):
    return SessionProcurer(sessions).procureSession(request)


style = Plating(tags=tags.html(
    tags.head(tags.title("yay")),
    tags.body(tags.div(slot(Plating.CONTENT))))
)

@style.routed(
    requirer.require(
        app.route("/", methods=["POST"]),
        foo=Field.integer(minimum=3, maximum=10), bar=Field.text(),
    ),
    tags.h1('u did it: ', slot("an-form-arg"))
)
def postHandler(foo, bar):
    return {"an-form-arg": foo}

@requirer.require(
    style.routed(
        app.route("/", methods=["GET"]),
        tags.div(slot("anForm"))
github twisted / klein / docs / introduction / codeexamples / template.py View on Github external
from struct import unpack

def random_from_string(string):
    return Random(
        unpack("!I", sha256(string.encode("utf-8")).digest()[:4])[0]
    )

from twisted.web.template import tags, slot
from klein import Klein, Plating
app = Klein()

myStyle = Plating(
    tags=tags.html(
        tags.head(tags.title(slot("pageTitle"))),
        tags.body(tags.h1(slot("pageTitle"), Class="titleHeading"),
                  tags.div(slot(Plating.CONTENT)))
    ),
    defaults={"pageTitle": "Places & Foods"}
)

@myStyle.routed(
    app.route("/"),
    tags.div(
        tags.h2("Sample Places:"),
        tags.ul([tags.li(tags.a(href=["/places/", place])(place))
                 for place in ["new york", "san francisco", "shanghai"]]),
        tags.h2("Sample Foods:"),
        tags.ul([tags.li(tags.a(href=["/foods/", food])(food))
                 for food in ["hamburgers", "cheeseburgers", "hot dogs"]]),
    ))
def root(request):
    return {}
github twisted / klein / loginspike.py View on Github external
)
                    ),
                    tags.li(
                        tags.form(Class="form-inline", action="/search")(
                            tags.input(Class="form-control", type="text",
                                       name="q",
                                       placeholder="Search"),
                            tags.button("Search",
                                        Class="btn btn-outline-success",
                                        type="submit")
                        )
                    )
                ),
            ),
            tags.div(Class="container")(
                slot(Plating.CONTENT)
            )
        )
    ),
    defaults={
        "homeActive": "",
        "loginActive": "",
        "signupActive": "",
        "sessionsActive": "",
    }
)

from sqlalchemy import Column, String, ForeignKey

import attr

@attr.s