缩进错误:使用unicode时应为缩进块



我收到这个错误:

缩进错误:使用unicode 时应为缩进块

但没有:

def __unicode__(self):
    return self.BankName

它工作正常。

我的型号.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教程中关于控制结构的部分,其中描述了多级缩进。

相关内容

  • 没有找到相关文章

最新更新