0
我是新的python。 考慮下面的代碼:'模塊'對象沒有屬性'模型'
from django.db import models
class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()
class Author(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=40)
email = models.EmailField()
class Book(models.Model):
title = models.CharField(max_length=100)
authors = models.ManyToManyField(Author)
publisher = models.ForeignKey(Publisher)
publication_date = models.DateField()
,這是我的項目結構:
爲什麼我得到這個錯誤時,要驗證?
'Module' Object Has no Attribute 'models'
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.1\helpers\pycharm\django_manage.py", line 41, in <module>
run_module(manage_file, None, '__main__', True)
File "C:\Python34\Lib\runpy.py", line 182, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "C:\Python34\Lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Python34\Lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:/Users/Shahr_000/PycharmProjects/HelloWorld\manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line
utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 354, in execute
django.setup()
File "C:\Python34\lib\site-packages\django\__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Python34\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models(all_models)
File "C:\Python34\lib\site-packages\django\apps\config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "C:\Python34\Lib\importlib\__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "C:/Users/Shahr_000/PycharmProjects/HelloWorld\HelloWorld\books\models.py", line 4, in <module>
class Publisher(models.Model):
AttributeError: 'module' object has no attribute 'Model'
您是否在models.py中有'Model'?也許你在這裏有一個錯字? (關於大寫和小寫的注意事項)(區分大小寫) – Kasramvd 2014-12-01 18:06:04
您是如何結束該項目結構的?至少從版本1.4開始,這不是做事情的方式,它不是'startproject'或'startapp'命令爲你創建的結構。 – 2014-12-01 18:10:42
@DanielRoseman我手動創建 – 2014-12-01 18:13:50