Twig 0.5.0
Twig is a backend web framework for python utilizing the socket module to handle http requests and serve responses.
To install use the following command:
py -m pip install TwigWeb
Changelog
0.5.0
0.4.0
0.3.0
0.2.0
Example
This example does not show all of the functionality of Twig. There is documentation currently being worked on.
from src.TwigWeb.backend.routehandler.route import Route, RouteParameter, RouteParamType
from src.TwigWeb.backend import Server
from src.TwigWeb.backend.response import Response
app = Server("", debug=True, open_root=False)
@app.route("")
def index(headers):
return Response("test", ContentType.html)
@app.route("form")
def form(headers):
return Response("""<form action="/page/2">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>""")
@app.route("page/[num]")
def index(headers, num):
return Response(f"num: {num} and {headers.URL}", ContentType.html)
@app.route("page")
def index(headers):
return Response(f"page", ContentType.html)
app.run()