没有模块名称书籍
No module name books
我在使用 django 的 python 服务器中出现以下错误。
C:\Users\Nuno\Favorites\Desktop\Django\mysiteproject>python manage.py runserver
Unhandled exception in thread started by <function wrapper at 0x03180B70>
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 229, in
wrapper
fn(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.
py", line 107, in inner_run
autoreload.raise_last_exception()
File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 252, in
raise_last_exception
six.reraise(*_exception)
File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 229, in
wrapper
fn(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 115, in pop
ulate
app_config.ready()
File "C:\Python27\lib\site-packages\django\contrib\admin\apps.py", line 22, in
ready
self.module.autodiscover()
File "C:\Python27\lib\site-packages\django\contrib\admin\__init__.py", line 24
, in autodiscover
autodiscover_modules('admin', register_to=site)
File "C:\Python27\lib\site-packages\django\utils\module_loading.py", line 74,
in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Users\Nuno\Favorites\Desktop\Django\mysiteproject\books\admin.py", li
ne 4, in <module>
from mysiteproject.books.models import Publisher, Author, Book
ImportError: No module named books.models
我的项目结构如下:
Django
books
migrations
__init__.py
0001_initial.py
__init__.py
admin.py
models.py
tests.py
views.py
mysiteproject
__init__.py
settings.py
urls.py
wsgi.py
views.py
templates
base.html
current_datetime.html
hours_ahead.html
books.db
manage.py
有人知道我做错了什么吗?
python版本:1.7.9
Django 版本:1.8.4
更改导入代码:
from mysiteproject.books.models import Publisher, Author, Book
至;
from books.models import Publisher, Author, Book
我在使用 django 的 python 服务器中出现以下错误。
C:\Users\Nuno\Favorites\Desktop\Django\mysiteproject>python manage.py runserver
Unhandled exception in thread started by <function wrapper at 0x03180B70>
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 229, in
wrapper
fn(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.
py", line 107, in inner_run
autoreload.raise_last_exception()
File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 252, in
raise_last_exception
six.reraise(*_exception)
File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 229, in
wrapper
fn(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 115, in pop
ulate
app_config.ready()
File "C:\Python27\lib\site-packages\django\contrib\admin\apps.py", line 22, in
ready
self.module.autodiscover()
File "C:\Python27\lib\site-packages\django\contrib\admin\__init__.py", line 24
, in autodiscover
autodiscover_modules('admin', register_to=site)
File "C:\Python27\lib\site-packages\django\utils\module_loading.py", line 74,
in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Users\Nuno\Favorites\Desktop\Django\mysiteproject\books\admin.py", li
ne 4, in <module>
from mysiteproject.books.models import Publisher, Author, Book
ImportError: No module named books.models
我的项目结构如下:
Django
books
migrations
__init__.py
0001_initial.py
__init__.py
admin.py
models.py
tests.py
views.py
mysiteproject
__init__.py
settings.py
urls.py
wsgi.py
views.py
templates
base.html
current_datetime.html
hours_ahead.html
books.db
manage.py
有人知道我做错了什么吗? python版本:1.7.9 Django 版本:1.8.4
更改导入代码:
from mysiteproject.books.models import Publisher, Author, Book
至;
from books.models import Publisher, Author, Book