我一直在嘗試運行此代碼,並且它引發縮進錯誤。無論我嘗試什麼,結果都是一樣的。意外的縮進錯誤,但縮進看起來正確
如果我在def __str__(self):
和其他代碼之前刪除了縮進,它可以正常工作,但是在輸出時,它不顯示問題,而是顯示「問題對象」。
def __str__(self):
^
IndentationError: unexpected indent
下面是代碼:
from __future__ import unicode_literals
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils import timezone
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.question_text
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __str__(self):
return self.choice_text
有空格你不混合標籤? –
你是如何縮進的?帶有製表符或空格? –
僅限使用空間。 4個空間塊 –