【问题标题】:When I run the Python code in Visual Studio Code Editor below, I get当我在下面的 Visual Studio 代码编辑器中运行 Python 代码时,我得到
【发布时间】:2020-01-23 06:34:05
【问题描述】:
def post(self, request, *args, **kwargs):
        post_data = request.data
        task_id = post_data.get("task_id")
        head = post_data.get("comment_head")
        value = post_data.get("comment_description")
        code = post_data.get("code")
        task = entity_Task(task_id=task_id)
        if task and head and value:
            try:
                if code and code == DELAY_FLAG_CODE:
                    entity_Comment.add_comment_flag_delay(
                        user=user, task_id=task_id, value=collection_feedback)
                else:
                    comment = entity_Comment.add_comment_with_task_id(
                        user=request.user, task_id=task_id, head=head, value=value)
                return JSONResponse({'code': 200, 'response': {"status": "Comment Saved"}})
            except Exception as e:
                xprint(e, traceback.format_exc())
                return JSONResponse({'code': 500, 'response': {"error": str(e)}});
        return JSONResponse({'code':200,'response':'Data Insufficient'})

在 vscode 编辑器中运行此代码后,我得到以下错误

IndentationError: unindent 不匹配任何外部缩进级别。

【问题讨论】:

  • 欢迎来到 Stack Overflow!您的标题不是很有帮助,请考虑编辑它。可能包括错误而不是您的 IDE 的名称。看看how to ask。在深入研究之后才提出要求也是 SA 的良好语气的一部分。如果你用 SA 或 google 搜索你的错误,我敢打赌你会发现很多有用的结果,因为它是标准的 python 东西。即使是 eth 第一次命中也可能对您有所帮助:stackoverflow.com/questions/492387/…

标签: python django


【解决方案1】:

找出此类内容的最简单方法是使用格式化程序(如black)来确保代码中的格式一致。在 VSCode 中,您可以使用 ctrl+shift+F 来格式化当前文件 - 这对于您当前的任务可能已经足够了。

否则,请检查回溯中的确切行并确保您的缩进正确/与文件/函数的其余部分匹配..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-03
    • 1970-01-01
    相关资源
    最近更新 更多