Python 2.7 测试期间无法禁用WTF CSRF保护

Python 2.7 测试期间无法禁用WTF CSRF保护,python-2.7,unit-testing,flask,flask-wtforms,csrf-protection,Python 2.7,Unit Testing,Flask,Flask Wtforms,Csrf Protection,在进行单元测试时,我无法确定如何禁用CSRF保护。 Mytest\u login()函数未通过unittest。当我调试时,我可以看到,csrf\u enabled值设置为True 文档中指出,app.config['WTF\u CSRF\u ENABLED']=False应该足够了,但这似乎不起作用 有人能告诉我如何禁用CSRF保护吗 谢谢 from flask.ext.testing import TestCase from flask import Flask from Shares i

在进行单元测试时,我无法确定如何禁用CSRF保护。

My
test\u login()
函数未通过unittest。当我调试时,我可以看到,
csrf\u enabled
值设置为
True

文档中指出,
app.config['WTF\u CSRF\u ENABLED']=False
应该足够了,但这似乎不起作用

有人能告诉我如何禁用CSRF保护吗

谢谢

from flask.ext.testing import TestCase
from flask import Flask
from Shares import db, app as appy
from Shares.models import User
import manage


class test(TestCase):

def create_app(self):
    app = Flask(__name__)
    app.config['TESTING'] = True
    app.config['WTF_CSRF_ENABLED'] = False
    return appy

SQLALCHEMY_DATABASE_URI = "sqlite://"
TESTING = True

def setUp(self):

    manage.initdb()
    print self.login('lucas', 'test').data

def tearDown(self):

    db.session.remove()
    db.drop_all()

def login(self, username, password):
    return self.client.post('/login', data=dict(
        username=username,
        password=password
    ), follow_redirects=True)

def logout(self):
    return self.client.get('/logout', follow_redirects=True)

def test_adduser(self):

    lucas=User(username="lucas", email="lucas@example.com", password="test")
    user2 = User(username="lucas", email="lucas@test.com")

    db.session.add(lucas)
    db.session.commit()

    assert lucas in db.session
    assert user2 not in db.session

def test_login(self):

    lucas=User(username="lucas", email="lucas@example.com", password="test")
    db.session.add(lucas)
    db.session.commit()

    rv = self.login('lucas', 'test')
    assert 'Welcome' in rv.data
我已经解决了

我的变量名应用程序&appy中有一个输入错误

def create_app(self):
    app = Flask(__name__)
    appy.config['TESTING'] = True
    appy.config['WTF_CSRF_ENABLED'] = False
    return appy