Very simple and tiny MTV-style, Django-(a little bit)-like web-framework. Allows to create web-pages (!!!) with Jinja2 template engine. Allowable HTTP-methods for every page can be chosen.
Handles 404 and 403 pages.
Distributed with example views and templates.
<Attention!> This module was made by mad-skilled student. Never use it in production. I said "NEVER". :) </Attention!>
To install this script using pip (auto install, requirements will be installed automatically):
$ pip install git+https://github.com/ravique/otus-framework.git
-
Download Nano Framework manually.
-
Install requirements:
$ pip install -r requirements.txt
Or install Jinja2 manually:
$ pip install Jinja2
You need to have configurated uWSGI-server.
uwsgi.ini entry points:
chdir = %path to wsgi.py%
module = wsgi:app
To create a web-page you need:
- Create view function for your page in framework/views.py. Function must have first positional argument 'request' string. Example:
def base_view(request, **kwargs):
return [b'Hello, OTUS']
- Add routing rule 'urls' dict in framework/urls.py.
Example:
'/': {'view': framework.views.mainpage_view, 'allowed_methods': ('GET', 'POST')},
Where:
'/'
– internal url,
'view': framework.views.mainpage_view
- your view function,
'allowed_methods': ('GET', 'POST')
– HTTP-methods allowed for your page. If you pass no allowed methods there,
page always will return 403 Forbidden.
- If you want, you can use Jinja2 template, create .html file in framework/templates. To use template in your view function:
template = env.get_template('index.html')
return render_template(template)
You can pass variables from view to your template.
Example:
render_template(template, foo='Foo', bar='Bar')
- Default 404 page included. It will be shown if user will reach any page, not listed in 'urls' dict.
- Pages with leading slash and without it return the same content.
- Andrei Etmanov - Student of OTUS :)
This project is licensed under the MIT License – see the LICENSE.md file for details