这是显示识别错误…为什么

2024-09-25 00:32:50 发布

您现在位置:Python中文网/ 问答频道 /正文

def snippet_list(request):
    """
    list all the code snippets ,or create a new snippet.
    """
    if request.method == 'GET':
        snippet = Snippet.object.all()
        serializer = SnippetSerializer(snippets, many = True)
        return JSONResponse(serializer.data)
    elif request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = SnippetSerializer(data =data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data,status =201)
        return JSONResponse(serializer.errors,status=400)

Tags: thedatareturnifrequestdefstatusall
1条回答
网友
1楼 · 发布于 2024-09-25 00:32:50

您正在混合制表符和空格:

indentation highlight

线表示制表符,点表示空格。Python将选项卡扩展到每第8列。你知道吗

不要混合制表符和空格,将制表符转换回空格,并将编辑器配置为仅使用空格进行缩进。你知道吗

您可以将大多数编辑器配置为仅使用空格进行缩进;这是Python styleguide (PEP 8)建议的:

Tabs or Spaces?

Never mix tabs and spaces.

The most popular way of indenting Python is with spaces only. The second-most popular way is with tabs only. Code indented with a mixture of tabs and spaces should be converted to using spaces exclusively. When invoking the Python command line interpreter with the -t option, it issues warnings about code that illegally mixes tabs and spaces. When using -tt these warnings become errors. These options are highly recommended!

For new projects, spaces-only are strongly recommended over tabs. Most editors have features that make this easy to do.

相关问题 更多 >