django创建model出错: ImportError: No module named
刀仔割大树 2016-02-01 02:09:42 环境:Django-1.9.1-py2.7 + centos 3.10.0 + mysql5.0
教程:http://www.runoob.com/django/django-model.html
我按着教程走,创建了HelloWorld的proj,之后创建TestModel的app,这时候我的目录是这样的:
[root@VM_9_170_centos HelloWorld]# tree
.
|-- HelloWorld
| |-- __init__.py
| |-- __init__.pyc
| |-- db.sqlite3
| |-- settings.py
| |-- settings.pyc
| |-- templates
| | |-- base.html
| | `-- hello.html
| |-- urls.py
| |-- urls.pyc
| |-- view.py
| |-- view.pyc
| |-- wsgi.py
| `-- wsgi.pyc
|-- TestModel
| |-- __init__.py
| |-- __init__.pyc
| |-- admin.py
| |-- admin.pyc
| |-- apps.py
| |-- migrations
| | `-- __init__.py
| |-- models.py
| |-- models.pyc
| |-- tests.py
| `-- views.py
|-- db.sqlite3
`-- manage.py
HelloWorld/settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'TestModel',
]
TestModel/models.py
class Test(models.Model):
name = models.CharField(max_length=20)
我执行命令: python manage.py syncdb
报错:
Unknown command: 'syncdb'
Type 'manage.py help' for usage.
我怀疑跟教程目录不一样,把TestModel mv 到HelloWorld里:
mv TestModel/ HelloWorld/
重新执行: python manage.py syncdb
报错:
[root@VM_9_170_centos HelloWorld]# python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 9, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib/python2.7/site-packages/Django-1.9.1-py2.7.egg/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/usr/lib/python2.7/site-packages/Django-1.9.1-py2.7.egg/django/core/management/__init__.py", line 327, in execute
django.setup()
File "/usr/lib/python2.7/site-packages/Django-1.9.1-py2.7.egg/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/lib/python2.7/site-packages/Django-1.9.1-py2.7.egg/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/lib/python2.7/site-packages/Django-1.9.1-py2.7.egg/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named TestModel
网上看了很多,基本都是版本问题,但是我这里INSTALLED_APPS应该没错。求助高手解答。