1
目前我使用Django 1.9和Django Rest Framework。我試圖使用獅身人面像,它是autodoc函數,但我在make html
上遇到錯誤。 models.py不會導入。獅身人面像:運行時錯誤django 1.9
myapp/
manage.py
index.rst
myapp/
__init__.py
settings.py
users/
models.py
source/
modules.rst
users.rst
settings.py
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'myapp',
'users',
)
,我得到的錯誤是:
WARNING: /home/sestrella/Devel/leroi-angular/source/customers.rst:10: (WARNING/2) autodoc: failed to import module u'users.models'; the following exception was raised:
Traceback (most recent call last):
File "/home/me/.virtualenvs/myapp/local/lib/python2.7/site-packages/sphinx/ext/autodoc.py", line 657, in import_object
__import__(self.modname)
File "/home/me/Devel/myapp/users/models.py", line 3, in <module>
from django.contrib.auth.models import User, Group
File "/home/me/.virtualenvs/myapp/local/lib/python2.7/site-packages/django/contrib/auth/models.py", line 6, in <module>
from django.contrib.contenttypes.models import ContentType
File "/home/me/.virtualenvs/myapp/local/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 161, in <module>
class ContentType(models.Model):
File "/home/me/.virtualenvs/myapp/local/lib/python2.7/site-packages/django/db/models/base.py", line 112, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
/home/me/Devel/myapp/source/modules.rst:4: WARNING: toctree contains reference to nonexisting document u'source/ users'
modules.rst
myapp
=============
.. toctree::
:maxdepth: 4
users
和users.rst
users
================
Modules
----------
users.models
----------------------
.. automodule:: users.models
:members:
:undoc-members:
:show-inheritance:
爲什麼users.models無法導入?我在我的users.models中使用ContentType模型作爲通用關係。