Python 2.7 如何在多个文件中拆分Flask代码

Python 2.7 如何在多个文件中拆分Flask代码,python-2.7,flask,couchdb,Python 2.7,Flask,Couchdb,将以下内容拆分为MVC的最佳方式是什么,以避免将所有内容都归档 # -*- coding: utf-8 -*- """ example/guestbook.py ==================== This is an example application for Flask-CouchDB. It's a simple guestbook that people can sign. :copyright: 2010 Matthew "LeafStorm" Frazier :lice

将以下内容拆分为MVC的最佳方式是什么,以避免将所有内容都归档

# -*- coding: utf-8 -*-
"""
example/guestbook.py 
====================
This is an example application for Flask-CouchDB. It's a simple guestbook that
people can sign.

:copyright: 2010 Matthew "LeafStorm" Frazier
:license:   MIT/X11, see LICENSE for details (part of Flask-CouchDB)
"""
import datetime
from flask import Flask, render_template, flash, request, redirect, url_for
from flaskext.couchdb import (CouchDBManager, Document, TextField,
              DateTimeField, ViewField, paginate)


# application setup
app = Flask(__name__)


# config
COUCHDB_SERVER = 'http://localhost:5984/'
COUCHDB_DATABASE = 'example-guestbook'
SECRET_KEY = 'set this to something secret'

app.config.from_object(__name__)


# model
class Signature(Document):
doc_type = 'signature'

message = TextField()
author = TextField()
time = DateTimeField(default=datetime.datetime.now)

all = ViewField('guestbook', '''
    function (doc) {
    if (doc.doc_type == 'signature') {
        emit(doc.time, doc);
    };
    }''', descending=True)


manager = CouchDBManager()
manager.add_document(Signature)
manager.setup(app)


# views
@app.route('/')
def display():
page = paginate(Signature.all(), 5, request.args.get('start'))
return render_template('display.html', page=page)


@app.route('/', methods=['POST'])
def post():
message = request.form.get('message')
author = request.form.get('author')
if not message or not author:
    flash("You must fill in both a message and an author")
else:
    signature = Signature(message=message, author=author)
    signature.store()
    flash("Signature stored")
return redirect(url_for('display'))


if __name__ == '__main__':
app.config.from_envvar('GUESTBOOK_SETTINGS', silent=True)
app.run(debug=True)

您可以查看官方文档:并从Github项目中获得灵感:。

我尝试了失败,并将代码放在Github上。如何修复它?您必须查看有关python模块的文档:。我为您提供回购并做了一些更改: