##Tiny - The tiniest possible web framework. Inspired by Flask, Bottle, and Itty.
To Install:
pip install tiny
To create a simple app:
import tiny, os
# Creates the app object.
app = tiny.TinyApp()
# Sets the path for the app to find HTML templates.
app.set_template_path(os.path.abspath('templates'))
## Routing ###
@app.route('/')
def index(request):
"""Defines the index view, accessible at '/'."""
# Creates a response comprised of the content of index.html and rendered template variables.
content = tiny.TinyResponse(app.render('index.html', template_var="Hello world"))
# Whatever is returned in a view will display on the page.
return content # Hello world
## HTTP Errors ##
@app.route('/505')
def error(request):
content = tiny.TinyResponse('HTTP Version Not Supported', 505)
return content
if __name__ == '__main__':
tiny.run_app(app) # Will be accessible at localhost:8080 by default.
To create a template:
<!-- index.html -->
{{ template_var }}
To run the test suite:
python tests/tests.py
>> ......
>> ----------------------------------------------------------------------
>> Ran 6 tests in 0.001s
>>
>> OK
-
To Do:
Implement WSGI interfaceParse HTTP GET requestSet up basic routing in request handlerHandle non-GET requestsParse queries more cleanlyHandle requests more intelligentlyHandle responses more intelligentlyMake decorator for creating URLsStore HTTP statuses somewhere- Move matching URLs into its own method
- Refactor rendering template method to be cleaner/more general
-
Overall Plan