I'm getting this error:
IndentationError: expected an indented block when use unicode
but without:
def __unicode__(self):
return self.BankName
it work correctly.
My 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
when typing 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
Please help me.
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
Please read the Python tutorial sections on control structures, which describes multi-level indentation .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.