簡體   English   中英

IndentationError:使用unicode時應縮進塊

[英]IndentationError: expected an indented block when use unicode

我收到此錯誤:

IndentationError:使用unicode時應縮進塊

但沒有:

def __unicode__(self):
    return self.BankName

它可以正常工作。

我的models.py:

from django.db import models
class Bank(models.Model):
    BankName=models.CharField(max_length=20)
    CardNum=models.CharField(max_length=20)
    def __unicode__(self):
    return self.BankName

當輸入python manage.py runserver

Validating models...
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x310f450>>
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 91, in inner_run
    self.validate(display_num_errors=True)
  File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 266, in validate
    num_errors = get_validation_errors(s, app)
  File "/usr/lib/python2.7/dist-packages/django/core/management/validation.py", line 30, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/usr/lib/python2.7/dist-packages/django/db/models/loading.py", line 158, in get_app_errors
    self._populate()
  File "/usr/lib/python2.7/dist-packages/django/db/models/loading.py", line 64, in _populate
    self.load_app(app_name, True)
  File "/usr/lib/python2.7/dist-packages/django/db/models/loading.py", line 88, in load_app
    models = import_module('.models', app_name)
  File "/usr/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/home/zahra/Web/rezvan/agancy/models.py", line 7
    return  self.BankName
         ^
IndentationError: expected an indented block

請幫我。

from django.db import models
class Bank(models.Model):
    BankName=models.CharField(max_length=20)
    CardNum=models.CharField(max_length=20)
    def __unicode__(self):
        return self.BankName

閱讀有關控制結構的Python教程部分,其中描述了多級縮進

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM