尝试在 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 对缩进敏感。确保:
- 您的所有代码都已正确缩进。一切都处于适当的水平。
- 您没有混合使用空格和制表符来缩进。这是人们通常陷入困境的地方。
希望这有帮助!
关于python - Django View : working with a file result in indentation error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20205177/