KeyError: 'A secret key is required to use CSRF.'

KeyError
KeyError: 'A secret key is required to use CSRF.'

Traceback (most recent call last)
File "/Users/huanglianggu/Desktop/artcms_project/venv/lib/python2.7/site-packages/flask/app.py", line 2309, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/huanglianggu/Desktop/artcms_project/venv/lib/python2.7/site-packages/flask/app.py", line 2295, in wsgi_app
response = self.handle_exception(e)
File "/Users/huanglianggu/Desktop/artcms_project/venv/lib/python2.7/site-packages/flask/app.py", line 1741, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/huanglianggu/Desktop/artcms_project/venv/lib/python2.7/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/Users/huanglianggu/Desktop/artcms_project/venv/lib/python2.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/huanglianggu/Desktop/artcms_project/venv/lib/python2.7/site-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/huanglianggu/Desktop/artcms_project/venv/lib/python2.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/huanglianggu/Desktop/artcms_project/venv/lib/python2.7/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/huanglianggu/Desktop/artcms_project/views.py", line 11, in login
form = LoginForm()
File "/Users/huanglianggu/Desktop/artcms_project/venv/lib/python2.7/site-packages/wtforms/form.py", line 212, in __call__
return type.__call__(cls, *args, **kwargs)
File "/Users/huanglianggu/Desktop/artcms_project/venv/lib/python2.7/site-packages/flask_wtf/form.py", line 88, in __init__
super(FlaskForm, self).__init__(formdata=formdata, **kwargs)
File "/Users/huanglianggu/Desktop/artcms_project/venv/lib/python2.7/site-packages/wtforms/form.py", line 278, in __init__
self.process(formdata, obj, data=data, **kwargs)
File "/Users/huanglianggu/Desktop/artcms_project/venv/lib/python2.7/site-packages/wtforms/form.py", line 132, in process
field.process(formdata)
File "/Users/huanglianggu/Desktop/artcms_project/venv/lib/python2.7/site-packages/wtforms/csrf/core.py", line 43, in process
self.current_token = self.csrf_impl.generate_csrf_token(self)
File "/Users/huanglianggu/Desktop/artcms_project/venv/lib/python2.7/site-packages/flask_wtf/csrf.py", line 134, in generate_csrf_token
token_key=self.meta.csrf_field_name
File "/Users/huanglianggu/Desktop/artcms_project/venv/lib/python2.7/site-packages/flask_wtf/csrf.py", line 35, in generate_csrf
message='A secret key is required to use CSRF.'
File "/Users/huanglianggu/Desktop/artcms_project/venv/lib/python2.7/site-packages/flask_wtf/csrf.py", line 121, in _get_config
raise KeyError(message)
KeyError: 'A secret key is required to use CSRF.'
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.

You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:

dump() shows all variables in the frame
dump(obj) dumps all that's known about the object

解决办法:

在/Users/huanglianggu/Desktop/artcms_project/views.py

添加

app.config["SECRET_KEY"] = "12345678"
# coding:utf8
from flask import Flask, render_template, redirect
from forms import LoginForm

app = Flask(__name__)
app.config["SECRET_KEY"] = "12345678"

 

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值