How to use the klein.Requirer 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 twisted.web.template import tags, slot
from klein import Klein, Plating, Form, Field, Requirer, SessionProcurer
from klein.interfaces import ISession
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(),
    ),
github twisted / klein / loginspike.py View on Github external
from twisted.web.util import Redirect

if TYPE_CHECKING:
    from hyperlink import DecodedURL
    # silence flake8 for type-checking
    (ISessionProcurer, Deferred, IRequest, Dict, Tag, Any, RenderableForm,
     ISessionStore, DecodedURL)

app = Klein()

def bootstrap(x):
    # type: (str) -> str
    return "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/" + x

requirer = Requirer()

style = Plating(
    tags=tags.html(
        tags.head(
            tags.link(rel="stylesheet",
                      href=bootstrap("css/bootstrap.min.css"),
                      crossorigin="anonymous"),
            # tags.script(
            #     src=bootstrap("js/bootstrap.min.js"),
            #     crossorigin="anonymous"
            # ),
            tags.title("hooray")
        ),
        tags.body(
            tags.nav(Class="navbar navbar-expand-lg navbar-light bg-light")(
                tags.a("Navbar", Class="navbar-brand",