【问题标题】:TabError inconsistent use of tabs and spaces in indentation [duplicate]TabError在缩进中不一致使用制表符和空格[重复]
【发布时间】:2020-04-04 12:53:07
【问题描述】:

views.py

from django.shortcuts import render
from django.http import HttpResponse
from .models import *

def home(request):
    return render(request, 'dashboard.html')

def products(request):
    products=product.objects.all()
    return render(request,'products.html', {'products':products})

def customer(request):
    return render(request, 'customer.html')

错误:

from . import views
  File "/Users/dileepkumar/Desktop/dj/accounts/views.py", line 12
    return render(request,'products.html', {'products':products})
                                                                ^
 TabError: inconsistent use of tabs and spaces in indentation

【问题讨论】:

  • 消息很清楚,您使用制表符和空格进行缩进。找到选项卡,然后用空格替换它们。
  • 那么如何将第 12 行周围的制表符更改为空格,因为错误消息告诉您,因为 python 对缩进非常敏感

标签: python django


【解决方案1】:

我的建议是使用任何文本编辑器,例如 VSCodeAtom,并使用内置功能“将缩进转换为空格”。

这些文本编辑器还允许您使用制表符进行缩进,同时自动在该位置插入所需数量的空格,以及使用文本编辑器进行编程的十几个其他原因。

【讨论】:

  • 是的,刚刚:)
猜你喜欢
  • 1970-01-01
  • 2015-08-28
  • 2019-04-15
  • 2020-01-23
  • 2019-07-24
  • 2020-08-10
  • 1970-01-01
  • 2022-11-12
  • 2016-05-23
相关资源
最近更新 更多