【问题标题】:IndentationError: unindent does not match any outer indentation level tutorialsIndentationError: unindent 不匹配任何外部缩进级别教程
【发布时间】:2017-02-02 08:02:49
【问题描述】:

这是我得到的输出:

我在这里学习了如何做到这一点: https://docs.djangoproject.com/en/1.10/intro/tutorial03/

我的代码是:

def index(request):
   latest_question_list = Question.objects.order_by('-pub_date')[:5]
   template = loader.get_template('polls/index.html')
   context = {
    '   latest_question_list': latest_question_list,
   }
   # output = ', '.join([q.question_text for q in latest_question_list])
   return HttpResponse(template.render(context, request))

这是引发的错误:

 File "C:\Users\ab\mysite\polls\views.py", line 9
   context = {
          ^
IndentationError: unindent does not match any outer indentation level

我做错了什么?

【问题讨论】:

  • 只需从 ' latest_question_list': latest_question_list, 中删除空格 ....
  • 感谢如此频繁的回复,但它不起作用
  • 深入了解缩进,例如混合空格和制表符?
  • rocksteady 一定是对的
  • 我的缩进是正确的,但错误仍然不断上升

标签: python django


【解决方案1】:

在运行 Python 时使用 -tt 选项。如果您混合使用制表符和空格,这将给您一个错误。

【讨论】:

    猜你喜欢
    • 2010-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多