私はPythonとFlaskが初めてです。私はこのチュートリアルを通して自分のやり方で取り組んでいます: http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iii-web-forms 今、私は見つけることができないエラーが発生していますの修正。Python 3.4.3 を再インストールし、仮想環境を再インストールしました。コードをチュートリアルから直接コピーして、入力中に間違いを犯していないことを確認しましたが、まだ何も機能しません。
初期化.py
from flask import Flask
app = Flask(__name__)
app.config.from_object('config')
from app import views
ビュー.py
from flask import render_template, flash, redirect
from app import app
from .forms import LoginForm
@app.route('/')
@app.route('/index')
def index():
user = {'nickname': 'Miguel'}
posts = [
{
'author': {'nickname': 'John'},
'body': 'Beautiful day in Portland!'
},
{
'author': {'nickname': 'Susan'},
'body': 'The Avengers movie was so cool!'
}
]
return render_template("index.html",
title='Home',
user=user,
posts=posts)
@app.route('/login', methods=['GET', 'POST'])
def login():
form = LoginForm()
return render_template('login.html',
title='Sign In',
form=form)
フォーム.py
from flask.ext.wtf import Form
from wtforms import StringField, BooleanField
from wtforms.validators import DataRequired
class LoginForm(Form):
openid = StringField('openid', validators=[DataRequired()])
remember_me = BooleanField('remember_me', default=False)
run.py
from app import app
app.run(debug=True)
エラー:
(flask) G:\microblog>python run.py
Traceback (most recent call last):
File "run.py", line 1, in <module>
from app import app
File "G:\microblog\app\__init__.py", line 6, in <module>
from app import views
File "G:\microblog\app\views.py", line 3, in <module>
from .forms import LoginForm
File "G:\microblog\app\forms.py", line 1, in <module>
from flask.ext.wtf import Form
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "G:\microblog\flask\lib\site-packages\flask\exthook.py", line 62, in load_module
__import__(realname)
File "G:\microblog\flask\lib\site-packages\flask_wtf\__init__.py", line 15, in <module>
from .form import Form
File "G:\microblog\flask\lib\site-packages\flask_wtf\form.py", line 15, in <module>
from .i18n import translations
File "G:\microblog\flask\lib\site-packages\flask_wtf\i18n.py", line 12, in <module>
from flask_babel import get_locale
File "G:\microblog\flask\lib\site-packages\flask_babel\__init__.py", line 21, in <module>
from babel import dates, numbers, support, Locale
File "G:\microblog\flask\lib\site-packages\babel\dates.py", line 28, in <module>
from babel.util import UTC, LOCALTZ
File "G:\microblog\flask\lib\site-packages\babel\util.py", line 278, in <module>
from babel import localtime
File "G:\microblog\flask\lib\site-packages\babel\localtime\__init__.py", line 21, in <module>
from babel.localtime._win32 import _get_localzone
File "G:\microblog\flask\lib\site-packages\babel\localtime\_win32.py", line 18, in <module>
tz_names = get_global('windows_zone_mapping')
File "G:\microblog\flask\lib\site-packages\babel\core.py", line 58, in get_global
_global_data = pickle.load(fileobj)
TypeError: an integer is required (got type str)
チュートリアルを続行できないことに不満を感じているので、どんな助けでも大歓迎です。