Metadata-Version: 2.1
Name: simple_http_server_jinja
Version: 0.1.1
Summary: This is a simple http server, use MVC like design.
Author-email: keijack <keijack.wu@gmail.com>
License: MIT License
        
        Copyright (c) 2018 Keijack Wu
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Project-URL: homepage, https://github.com/keijack/python-simple-http-server-jinja
Project-URL: repository, https://github.com/keijack/python-simple-http-server-jinja
Keywords: http-server,jinja,http,web,web-server
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: simple-http-server >=0.14
Requires-Dist: jinja2 >=3.1

# 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
```

```python
from simple_http_server import route, server
from simple_http_server_jinja import JinjaView, render

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

@route("/page")
def page():
    return 200, render("page.html", {"a": "b"})

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
|----page.html
|--main.py
```

You can set your own Jinja2 Environment via `set_env` function:

```python
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()
```
