Skip to main content

This is a simple http server, use MVC like design.

Project description

Jinja for Python Simple Http Server

What's this?

This is a Jinja extension for pythone simple http server (https://github.com/keijack/python-simple-http-server)

How to use?

install

python3 -m pip install simple_http_server_jinja
from simple_http_server import route, server
from simple_http_server_jinja import JinjaView

@route("/index")
def index(name: str = "world"):
    return JinjaView("index.html", {"name": name})

def main():
    server.start(port=9090)

if __name__ == "__main__":
    main()

For the above code, the templates should be placed in the templates folder in your project's root.

|--templates
|----index.html
|--main.py

You can set your own Jinja2 Environment via set_env function:

from simple_http_server import route, server
from simple_http_server_jinja import JinjaView, set_env
from jinja2 import Environment, FileSystemLoader

@route("/index")
def index(name: str = "world"):
    return JinjaView("index.html", {"name": name})

def main():
    env = Environment(loader=FileSystemLoader("/you/own/template/folder"))
    set_env(env)
    server.start(port=9090)

if __name__ == "__main__":
    main()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple_http_server_jinja-0.1.0.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_http_server_jinja-0.1.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file simple_http_server_jinja-0.1.0.tar.gz.

File metadata

File hashes

Hashes for simple_http_server_jinja-0.1.0.tar.gz
Algorithm Hash digest
SHA256 52464a9a03332800a801319b199c08b7f3d1ddcd26e8a67016273bdab36a8658
MD5 58d38b6e5483e3042456f8c1729a401a
BLAKE2b-256 a5174390cb7662bd9c04c72af5e73c8ec843fda811eb0422a423e03813975e5d

See more details on using hashes here.

File details

Details for the file simple_http_server_jinja-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_http_server_jinja-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 55229805752cd1afc2899d60e5c38ec9ac820f5f8944f3d1616c7a4d3a17ba8c
MD5 2063d4732d45b1294f28b815d0cbc736
BLAKE2b-256 5aae6c85035cc6a7fa11e93f26e2ded1f00759161adc81fb58b5946a97b9943d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page