2015-07-20 60 views
2

所以我在線做這個教程「https://www.youtube.com/watch?v=KqN4u28T-JQ」,我得到這個錯誤。我盡力找出我做錯了什麼,我很難過。attributeError:「模塊」對象沒有任何屬性「DateTimeField」

我的admin.py文件

from django.contrib import admin 

# Register your models here. 
from blog.models import Post 

admin.site.register(Post) 

我的models.py文件

models.py 
from django.db import models 

# Create your models here. 
class Post(models.Model): 
    title = models.CharField(max_length = 140) 
    body = models.TextField() 
    date = models.DateTimeFeild() 

    def __unicode__(self): 
     return self.title 

當我把manage.py執行syncdb到控制檯返回的值。

C:\Users\user\Desktop\mysite\mysite>manage.py syncdb 
    Traceback (most recent call last): 
     File "C:\Users\user\Desktop\mysite\mysite\manage.py", line 10, in <module> 
     execute_from_command_line(sys.argv) 
     File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\core\managem 
    ent\__init__.py", line 338, in execute_from_command_line 
     utility.execute() 
     File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\core\managem 
    ent\__init__.py", line 312, in execute 
     django.setup() 
     File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\__init__.py" 
    , line 18, in setup 
     apps.populate(settings.INSTALLED_APPS) 
     File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\apps\registr 
    y.py", line 108, in populate 
     app_config.import_models(all_models) 
     File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\apps\config. 
    py", line 198, in import_models 
     self.models_module = import_module(models_module_name) 
     File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module 
     __import__(name) 
     File "C:\Users\user\Desktop\mysite\mysite\blog\models.py", line 4, in <modul 
    e> 
     class Post(models.Model): 
     File "C:\Users\user\Desktop\mysite\mysite\blog\models.py", line 7, in Post 
     date = models.DateTimeFeild() 
    AttributeError: 'module' object has no attribute 'DateTimeFeild' 
+0

你能解釋一下你想做什麼嗎? – Cleb

+3

請注意錯誤。你有一個錯字:'DateTimeFeild'。 –

+0

UHGHGHGHGH尷尬DateTimeFeild錯字 –

回答

0

看起來你有一個錯字:S /費爾德/現場/ g的

0
from __future__ import unicode_literals 
from django.db import models 
# Create your models here. 
from django.db import models 
class BlogPost(models.Model): 
    title = models.CharField(max_length = 150) 
    body = models.TextField() 
    timestamp = models.DataTimeField() 

./manage.py遷移 ... AttributeError的: '模塊' 對象有沒有屬性「DataTimeField 「

這個怎麼樣,我只是不知道哪裏錯了

0

也許你可以代替試試這個:

date = models.DateFeild() 
+0

這個答案是錯誤的寫的是DateField()而不是DateFeild() –

相關問題