例如,我有以下序列化器:
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = (
'userid',
'password'
)
Run Code Online (Sandbox Code Playgroud)
但我不想在GET上输出密码(当然我的真实例子还有其他字段).如果不编写其他序列化程序,我怎么能这样做?即时更改字段列表.有没有办法做到这一点?
Flask 400exception(abort())的默认消息是:
{
"message": "The browser (or proxy) sent a request that this server could not understand."
}
Run Code Online (Sandbox Code Playgroud)
用于404:
{
"message": "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again. You have requested this URI [/obj/] but did you mean /obj/ or /obj/<int:id>/ or /obj/<int:id>/kill/ ?"
}
Run Code Online (Sandbox Code Playgroud)
当我将它们作为我的API中的回复(特别是第一个,我认为加密或标题有问题)时,我无法理解这些消息.我觉得尝试为每个abort()异常手动覆盖文本都很烦人.所以我改变了映射:
from flask import abort
from werkzeug.exceptions import HTTPException
class BadRequest(HTTPException):
code = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用click来存储多个文件.例如:
@cli.command("test")
@click.argument('input', type=click.File('rb'))
def test(input):
with click.progressbar(input, label='READING') as bar:
for x in bar:
pass
Run Code Online (Sandbox Code Playgroud)
当我做这样的事情时:
script test ~/ololo/*
Run Code Online (Sandbox Code Playgroud)
我明白了:
Error: Got unexpected extra arguments ( ... listing all files in folder ...)
Run Code Online (Sandbox Code Playgroud) final Button OptButton = (Button) findViewById(R.id.OptButton);
OptButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent OptionsSc = new Intent(this, OptionsActivity.class);
startActivity (OptionsSc);
}
});
Run Code Online (Sandbox Code Playgroud)
Eclipse一直强调这new Intent(this, OptionsActivity.class);部分,我不明白为什么.以前,对OptionsActivity的调用已分配给硬件搜索按钮,一切正常.
好的,问题是:在Zed Shaw的"学习Python艰难之路" 练习49中,我们需要测试几个例外assert_raises().这是我正在测试的函数,如果省略该assert_raises()部分,它会通过测试:
def parse_verb(word_list):
skip(word_list, 'stop')
if peek(word_list) == 'verb':
return match(word_list, 'verb')
else:
raise ParserError("Expected a verb next.")
Run Code Online (Sandbox Code Playgroud)
这是测试功能和臭名昭着的assert_raises()线:
def parse_verb_test():
vrb_list = [('of', 'stop'), ('from', 'stop'), ('go', 'verb'), ('north', 'direction')]
assert_equal(parse_verb(vrb_list), ('go', 'verb'))
assert_equal(vrb_list, [('north', 'direction')])
assert_raises(ParserError, parse_verb, vrb_list)
Run Code Online (Sandbox Code Playgroud)
它给了我以下输出:
.........E...
======================================================================
ERROR: tests.parser_tests.parse_verb_test
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/vsevolod/Repositories/ex48/tests/parser_tests.py", line 20, in parse_verb_test
assert_raises(ParserError, parse_verb, vrb_list)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py", line 471, …Run Code Online (Sandbox Code Playgroud)