使用 Django(它是新手,通常是 Python 新手)来做一个非常基本的联系人数据库。
尝试通过 Admin 页面将记录添加到 Contributor 表,其模型代码为:
class Contributor(models.Model):
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20)
organisation = models.ForeignKey('Organisation')
mode = models.CharField(max_length=10, blank=True)
email = models.CharField(max_length=30, blank=True)
landline = models.CharField(max_length=10, blank=True)
def __unicode__(self):
print('%s %s' % (self.first_name, self.last_name))
我收到的错误消息是:
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/ramapp/contributor/add/
Django Version: 1.5.5
Python Version: 2.7.5
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'south',
'ramapp')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "/Users/lemon/.virtualenvs/ram/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
File "/Users/lemon/.virtualenvs/ram/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
372. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Users/lemon/.virtualenvs/ram/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
91. response = view_func(request, *args, **kwargs)
File "/Users/lemon/.virtualenvs/ram/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
89. response = view_func(request, *args, **kwargs)
File "/Users/lemon/.virtualenvs/ram/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
202. return view(request, *args, **kwargs)
File "/Users/lemon/.virtualenvs/ram/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
25. return bound_func(*args, **kwargs)
File "/Users/lemon/.virtualenvs/ram/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
91. response = view_func(request, *args, **kwargs)
File "/Users/lemon/.virtualenvs/ram/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
21. return func(self, *args2, **kwargs2)
File "/Users/lemon/.virtualenvs/ram/lib/python2.7/site-packages/django/db/transaction.py" in inner
223. return func(*args, **kwargs)
File "/Users/lemon/.virtualenvs/ram/lib/python2.7/site-packages/django/contrib/admin/options.py" in add_view
1009. self.log_addition(request, new_object)
File "/Users/lemon/.virtualenvs/ram/lib/python2.7/site-packages/django/contrib/admin/options.py" in log_addition
530. action_flag = ADDITION
File "/Users/lemon/.virtualenvs/ram/lib/python2.7/site-packages/django/contrib/admin/models.py" in log_action
18. e = self.model(None, None, user_id, content_type_id, smart_text(object_id), object_repr[:200], action_flag, change_message)
Exception Type: TypeError at /admin/ramapp/contributor/add/
Exception Value: 'NoneType' object has no attribute '__getitem__'
感谢任何帮助。挣扎!谢谢。
马特