如何解决IndentationError: python脚本中意外缩进问题

2024-04-24 11:31:00 发布

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

我的python代码有问题。我认为我使用了正确的python结构,但它一直在显示我(意外的缩进错误)

class TopGamesPostPage(Handler):
    def get(self):
        self.render("topgamespost.html")

    def post(self):
        title = self.request.get('title')
        info = self.request.get('info')

        if title and info: --> unexpected indent error
            p = Post(parent = blog_key(), title = title, info=info)
            p.put()
            self.redirect('/topgames/%s' % str(p.key().id()))
        else:
            error = "subject and content, please!"
            self.render("topgamespost.html", title=title, info=info, error=error)

Tags: andkey代码selfinfogettitlerequest
2条回答

可能有很多原因,例如混合制表符和空格、隐藏的unicode字符等。请粘贴code causing problem here的部分。它会告诉你确切的问题。

由于Python希望同一级别的每一个缩进行中的空白完全相同,并且空白“长度”在编辑器中看起来相同,所以可能是文件中混合了制表符和空格。

相关问题 更多 >