Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法实现_str_()方法并使其在cmd中运行_Python_Django_Api - Fatal编程技术网

Python 无法实现_str_()方法并使其在cmd中运行

Python 无法实现_str_()方法并使其在cmd中运行,python,django,api,Python,Django,Api,我首先写下了使对象更易于阅读的方法,但当我在cmd中运行对象时,它不起作用。就在我运行django内置API之后python manage.py shell。然而,当我运行Question.objects.all()时,它仍然会返回这个结果。当我运行它时,它会返回,我的结果应该返回替换: def _str_(self): ..... 与: 双下划线,而不是单下划线。\uuuu str\uuuuu不是\u str\uuu。我试过了,但当我运行它时,给我一个名字错误:名字“问题未定义”点击

我首先写下了使对象更易于阅读的方法,但当我在cmd中运行对象时,它不起作用。就在我运行django内置API之后
python manage.py shell
。然而,当我运行
Question.objects.all()
时,它仍然会返回这个结果。当我运行它时,它会返回
,我的结果应该返回
替换:

def _str_(self):
    .....
与:


双下划线,而不是单下划线。

\uuuu str\uuuuu
不是
\u str\uuu
。我试过了,但当我运行它时,给我一个名字错误:名字“问题未定义”点击它。它能用,谢谢!:)
def _str_(self):
    .....
def __str__(self):
    .....