python - flask Blueprint file structure -
i have troubles flask blueprint
structure of project:
hw ...run.py ...sigcontoj ......__init__.py ......admin .........__init__.py .........views.py .........models.py ......frontend .........__init__.py .........views.py .........models.py run.py:
from sigcontoj import create_app sigcontoj.frontend import frontend app = create_app(__name__) if __name__ == '__main__': print app.url_map print app.blueprints app.run(debug = true) sigcontoj__init__.py:
from flask import flask flask.ext.sqlalchemy import sqlalchemy sigcontoj.frontend import frontend db = sqlalchemy() def create_app(name=__name__): app = flask(name, static_path='/static') app.register_blueprint(frontend, url_prefix=none) app.secret_key = 'dfsdf1323jlsdjfl' app.config['sqlalchemy_database_uri'] = 'sqlite:///soj.db' db.init_app(app) return app sigcontoj\frontend__init__.py:
from flask import blueprint frontend = blueprint('frontend', __name__, template_folder='templates') sigcontoj\frontend\models.py:
from datetime import datetime sigcontoj import db class news(db.model): id = db.column(db.integer, primary_key=true) title = db.column(db.string(256)) content = db.column(db.text) publish_time = db.column(db.datetime, default=datetime.now()) def __repr__(self): return '<news : %s>' % self.title sigcontoj\frontend\views.py:
from sigcontoj.frontend.models import news sigcontoj.frontend import frontend @frontend.route('/') def index(): news = news.query.all()[0:5] return "hello world" the output of app.url_map is
map([' (head, options, get) -> static>])
and index page 404.
are there mistake in code?
the issue have though import frontend blueprint since never import views index (/) route never registered frontend. if update sigcontoj/__init__.py import sigcontoj.frontend.views:
from flask import flask flask.ext.sqlalchemy import sqlalchemy sigcontoj.frontend import frontend import sigcontoj.frontend.views then should work.
Comments
Post a Comment