在我的Mac 10.8.5上运行Django服务器时出错

时间:2013-10-03 13:33:49

标签: python django macos

我正在尝试在我的Mac上设置Python / Django / Mysql,但是当我在终端中运行此命令时,我一直收到以下错误

Python manage.py runserver

我得到的错误是

Marks-MacBook-Air:FirstBlog mmillar$ 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 0x1017c2b10>>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 92, in inner_run
self.validate(display_num_errors=True)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 280, in validate
 num_errors = get_validation_errors(s, app)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/validation.py", line 35, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/loading.py", line 166, in get_app_errors
self._populate()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/loading.py", line 72, in _populate
self.load_app(app_name, True)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/loading.py", line 96, in load_app
models = import_module('.models', app_name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/mmillar/PycharmProjects/FirstBlog/blog/models.py", line 5, in <module>
class post(models.Model):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/base.py", line 145, in __new__
new_class.add_to_class(obj_name, obj)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/base.py", line 265, in add_to_class
value.contribute_to_class(cls, name)
TypeError: Error when calling the metaclass bases
unbound method contribute_to_class() must be called with TextField instance as first argument (got ModelBase instance instead)

models.py

from django.db import models 
# Create your models here. 

class post(models.Model): 
    author = models.CharField(max_length=30) 
    title = models.CharField(max_length=100) 
    bodytext = models.TextField 
    timestamp = models.DateTimeField 

2 个答案:

答案 0 :(得分:0)

我认为你做过类似的事情:

错误:

class Foo(models.Model):
    bar = models.TextField

正确的:

class Foo(models.Model):
    bar = models.TextField()

因此,您尝试使用类而不是类实例进行验证。

答案 1 :(得分:0)

你的models.py必须如下:

from django.db import models 
# Create your models here. 

class post(models.Model): 
    author = models.CharField(max_length=30) 
    title = models.CharField(max_length=100) 
    bodytext = models.TextField()
    timestamp = models.DateTimeField() 

Cause unbound method contribute_to_class() TypeError - 表示

  

“模型字段未正确声明,括号后面   字段类型名称缺少“

您有两个字段缺少括号:

bodytext = models.TextField 
timestamp = models.DateTimeField