FPage is a tornado classic project generator(cli).
classic
means the style before separation of front-end and backend became popular.
Quick start a project with tornado + mako/jinja2 + peewee/sqlalchemy。
pip install fpage
fpage new [project-name]
or
python fpage.py new [project-name]
Step by step:
Type your project name.
Choose template engine (Mako/Jinja2/Tornado)
Choose the ORM you like best(Peewee/SQLChemy)
Enter Y to confirm.
Now here is a directory, it's protype of your project.
Run python app.py
, and access http://127.0.0.1:9000 to check.
Example:
# fpage new test_project
Project Name (test_project):
Template Engine [M/J/T]:
Database ORM [P/S]:
Project Name: test_project
Template Engine: mako
Database ORM: peewee
Sure (Y/n)?
Complete.
To get started:
cd test_project
python app.py
Served at http://localhost:9000
based on tornado
MVT Pattern (Model, View, Template)
compatible with python 3 & python 2
secure support (secure cookie, xsrf)
URL Route decorator like flask (@route)
simple session support(based on secure cookie)
choose your favourite template engine (mako/jinjia2/tornado)
defined template variable: req static url_for csrf_token/xsrf_token config
choose your favourite ORM sqlalchemy/peewee
message flashing (like of messages django, and flash of flask)
simple user system
page title help tool
a filter extension for peewee's model_to_dict
paginator
model
view
templates
lib - tools
URL Route decorator like flask (@route)
from view import route, url_for, View
@route('/')
class Index(View):
def get(self):
self.render()
def post(self):
pass
@route('/about', name='about')
class About(View):
def get(self):
self.render()
Simple session support(based on secure cookie)
@route('/')
class Index(View):
def get(self):
self.session['test'] = 'session test 1'
del self.session['test']
self.session['test'] = 'session test 2'
self.render(s=self.session['test'])
Choose your favourite template engine (mako/jinjia2/tornado)
<body>
${self.body()}
<%block name="script"/>
</body>
<body>
{% block body %}{% endblock %}
{% block script %}{% endblock %}
</body>
Defined template variable: req static url_for csrf_token/xsrf_token config
req -> request object
${ req.current_user }
static -> static file
<script src="${ static('js/main.js') }"></script>
<link rel="stylesheet" href="${ static('css/style.css') }">
url_for -> url reverse
<p><a href="${ url_for('jump') }">Jump Page</a></p>
<p><a href="${ url_for('about') }">About Page</a></p>
csrf_token -> self.xsrf_form_html()
<form method="post" class="am-form">
${csrf_token}
</form>
Choose your favourite ORM sqlalchemy/peewee
config
DATABASE_URI = "sqlite:///database.db"
sqlalchemy
from model import BaseModel
from sqlalchemy import Column, Integer, String, Float, ForeignKey, Boolean
class Test(BaseModel):
__tablename__ = 'test'
id = Column(Integer, primary_key=True, autoincrement=True)
test = Column(String)
peewee
from peewee import *
from model import BaseModel
class Test(BaseModel):
test = TextField()
Message flashing (like of messages django, and flash of flask)
view
@route('/jump_test', name='jump')
class Jump(View):
def get(self):
self.messages.error('Message Test: Error!!')
self.redirect(url_for('about'))
template
% for msg in get_messages():
% if msg.tag == 'success':
<div class="ui-green">
${msg.txt}
</div>
% elif msg.tag == 'error':
<div class="ui-red">
${msg.txt}
</div>
% endif
% endfor
a filter extension for peewee
see lib/pvpatch.py
Page title help tool
config
config.TITLE = 'FPage'
View
self.render(page_title=page_title('Test Board', 'Forum')
The title of page: Test Board » Forum » FPage
paginator
model.pagination_peewee / model.pagination_sqlalchemy
Definition:
def pagination(count_all, query, page_size, cur_page=1, nearby=2):
pass
Return:
{
'cur_page': cur_page,
'prev_page': prev_page,
'next_page': next_page,
'first_page': first_page,
'last_page': last_page,
'page_numbers': list(items),
'page_count': page_count,
'items': [...],
'info': {
'page_size': page_size,
'count_all': count_all,
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。