当我试图使用热水瓶包装顶部的管理脚本时,出现了一个错误。我真的很想知道如何解决这个错误。我想在某个地方出现了错误,我无法理解。我使用的是Flask 0.12。 我正在学习如何使用烧瓶目录树:
README.rst manage.py thermos
./thermos:
__init__.py forms.py models.py static thermos.db views.py
__init__.pyc forms.pyc models.pyc templates thermos.pyc views.pyc
./thermos/static:
css img js
./thermos/static/css:
main.css normalize.css normalize.min.css
./thermos/static/img:
./thermos/static/js:
main.js vendor
./thermos/static/js/vendor:
jquery-1.11.2.min.js modernizr-2.8.3-respond-1.4.2.min.js
./thermos/templates:
404.html add.html base.html form_macros.html index.html
运行python时管理.pyrunserver引发了此错误:
^{pr2}$这是管理.py公司名称:
#! /usr/bin/env python
from flask_script import Manager,prompt_bool
from thermos import app,db
import thermos.models
manager = Manager(app)
@manager.command
def initdb():
db.create_all()
db.session.add(User(username='olatunji',email='ayo19602003@yahoo.com'))
db.session.add(User(username='ayobami',email='bambamaks37@gmail.com'))
db.session.commit()
print "Initialized the database"
@manager.command
def dropdb():
if prompt_bool(
"Are you sure you want to lose all your data"):
db.drop_all()
print 'Dropped the database'
if __name__ == '__main__':
manager.run()
以及初始化.py:
import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
basedir = os.path.abspath(os.path.dirname(__file__))
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI']= 'sqlite:///' + os.path.join(basedir,'thermos.db')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['DEBUG'] = True
db = SQLAlchemy(app)
import models
import views
这是视图.py公司名称:
from flask import render_template,flash,redirect,url_for
from thermos import app,db
from forms import BookmarkForm
from models import User,Bookmark
def logged_in_user():
return User.query.filter_by(username='olatunji').first()
@app.route('/index')
def index():
return render_template('index.html',new_bookmarks=Bookmark.newest(5))
@app.route('/add',methods=['GET','POST'])
def add():
form = BookmarkForm()
if form.validate_on_submit():
url = form.url.data
description =form.description.data
bm = Bookmark(user=logged_in_user(),url=url,description=description)
db.session.add(bm)
db.session.commit()
flash("Stored '{}'".format(description))
return redirect(url_for('index'))
return render_template('add.html',form=form)
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'),404
@app.errorhandler(500)
def server_error(e):
return render_template('500.html'),500
if __name__ == '__main__':
app.run(debug=False)
错误停止后,我更正了一些打字错误。在
The __init__.py
:在管理.py公司名称:
^{pr2}$以及视图.py公司名称:
相关问题 更多 >
编程相关推荐