python - Django View : working with a file result in indentation error

标签 python django

尝试在 django 中编写以下 View :

def amenity(request):
    f = open('some_file.txt', 'w+')
    f.write("text")
    f.close()
    return HttpResponse("Done")

从浏览器调用它会导致以下错误

Exception Type: IndentationError
Exception Value: unindent does not match any outer indentation level (views.py, line 19)

最佳答案

嗯,IndentationError 表示存在缩进错误!

Python 对缩进敏感。确保:

  1. 您的所有代码都已正确缩进。一切都处于适当的水平。
  2. 您没有混合使用空格和制表符来缩进。这是人们通常陷入困境的地方。

希望这有帮助!

关于python - Django View : working with a file result in indentation error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20205177/

相关文章:

python - Python 中可能存在真正的动态和匿名函数吗?

javascript - Json 转储到单独的变量

Django Microsoft 身份验证后端在新部署中未成功

python - 如何使用网格几何管理器调整 TkInter 标签的绝对大小而不是附加空间

python - Django REST Framework - 在 URL 中添加 2 个 PK

python - Django 中的 AttributeError at/circular/1/detail/'CircularDetail' 对象没有属性 'pk'

python - 模板不存在于/accounts/login

django - 在SearchResult django haystack的数据库中找不到对象

python - Chromedriver 文本文件忙

python - Django : Can I Pre-fill forms with a model instance datas in form. py?