问题描述
我在 Learn hard way Python 的 ex51 中的鼻子测试中收到错误(ValueError:源代码刺痛不能包含空字节),尽管我的代码与书中的代码相同。
app.py
from flask import Flask,render_template
from flask import request
app = Flask(__name__)
@app.route('/hello/',methods=['POST','GET'])
def index():
greeting = "Hello World"
if request.method == 'POST':
name = request.form['name']
greet = request.form['greet']
greeting = f"{greet},{name}"
return render_template('index.html',greeting=greeting)
else:
return render_template('hello_form.html')
if __name__ == '__main__':
app.run()
app_tests.py
from nose.tools import *
from app import app
app.config['TESTING'] = True
web = app.test_client()
def test_index():
rv = web.get('/',follow_redirects=True)
assert_equal(rv.status_code,404)
rv = web.get('/hello',200)
assert_in(b"Fill Out This Form",rv.data)
data = {'name': 'Zed','greet': 'Hola'}
rv = web.post('/hello',follow_redirects=True,data=data)
assert_in(b"Zed",rv.data)
assert_in(b"Hola",rv.data)
我尝试在代码中查找空字节并更改编码格式,但没有成功。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)