狮身人面像:运行时错误django 1.9

问题描述:

目前我使用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模型作为通用关系。

我不知道这是一个错误的修复,或替代方法:

在conf.py

,添加:

import django 
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings' 
django.setup()