IndentationError:使用unicode时预计会出现缩进块

时间:2015-07-09 22:55:21

标签: python

我收到了这个错误:

  

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

请帮帮我。

1 个答案:

答案 0 :(得分:0)

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

read the Python tutorial sections on control structures, which describes multi-level indentation