5
試圖安裝Python和燒瓶內的登錄頁面的工作,卻得到了錯誤: (33行是與@login_required
)Python的燒瓶包裹
Traceback (most recent call last):
File "routes.py", line 33, in <module>
@login_required
File "/home/pi/FlaskTutorial/local/lib/python2.7/site-packages/flask/app.py", line 1013, in decorator
self.add_url_rule(rule, endpoint, f, **options)
File "/home/pi/FlaskTutorial/local/lib/python2.7/site-packages/flask/app.py", line 62, in wrapper_func
return f(self, *args, **kwargs)
File "/home/pi/FlaskTutorial/local/lib/python2.7/site-packages/flask/app.py", line 942, in add_url_rule
endpoint = _endpoint_from_view_func(view_func)
File "/home/pi/FlaskTutorial/local/lib/python2.7/site-packages/flask/helpers.py", line 60, in _endpoint_from_view_func
assert view_func is not None, 'expected view func if endpoint ' \
AssertionError: expected view func if endpoint is not provided.
這裏是我使用的代碼,我似乎無法找到問題...任何想法?
from flask import *
from functools import wraps
app = Flask(__name__)
app.secret_key = 'secret key' #Use a random key generator
@app.route('/')
def home():
return render_template('home.html')
@app.route('/welcome')
def welcome():
return render_template('welcome.html')
def login_required(test):
@wraps(test)
def wrap(*args, **kwargs):
if 'logged_in' in session:
return test(*args, **kwargs)
else:
flash('You need to login first.')
return redirect(url_for('log'))
return wrap
@app.route('/logout')
def logout():
session.pop('logged_in', None)
flash('You were logged out')
return redirect (url_for('log'))
@app.route('/hello')
@login_required
def hello():
return render_template('hello.html')
@app.route('/log', methods=['GET', 'POST'])
def log():
error = None
if request.method =='POST':
if request.form['username'] != 'admin' or request.form['password'] != 'admin':
error = 'Invaled Credentials. Please try again.'
else:
session['logged_in'] = True
return redirect(url_for('hello'))
return render_template('log.html', error=error)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=9000, debug=True)
謝謝,你盯着它,只要你不能通過樹林看到森林...再次感謝 – user2740536
感謝碰巧遇到同樣的問題。 –