当前位置:  开发笔记 > 编程语言 > 正文

ImportError:在安装的应用程序中输入'registration'时无法导入名称RequestSite

如何解决《ImportError:在安装的应用程序中输入'registration'时无法导入名称RequestSite》经验,为你挑选了2个好方法。

我正在尝试安装并运行Django-registration-redux,每当我尝试在已安装的应用程序中包含"注册"时,我都会收到错误消息:

Traceback (most recent call last):
  File "C:\Users\AdamSmith\projects\myvenv\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\AdamSmith\projects\myvenv\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "C:\Users\AdamSmith\projects\myvenv\lib\site-packages\django\utils\autoreload.py", line 249, in raise_last_exception
    six.reraise(*_exception)
  File "C:\Users\AdamSmith\projects\myvenv\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\AdamSmith\projects\myvenv\lib\site-packages\django\__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\AdamSmith\projects\myvenv\lib\site-packages\django\apps\registry.py", line 115, in populate
    app_config.ready()
  File "C:\Users\AdamSmith\projects\myvenv\lib\site-packages\django\contrib\admin\apps.py", line 22, in ready
    self.module.autodiscover()
  File "C:\Users\AdamSmith\projects\myvenv\lib\site-packages\django\contrib\admin\__init__.py", line 26, in autodiscover
    autodiscover_modules('admin', register_to=site)
  File "C:\Users\AdamSmith\projects\myvenv\lib\site-packages\django\utils\module_loading.py", line 50, 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\AdamSmith\projects\myvenv\lib\site-packages\registration\admin.py", line 2, in 
    from django.contrib.sites.models import RequestSite
ImportError: cannot import name RequestSite

我已经在myenv virtualenv中新安装了Django.manage.py runserver工作正常,加载管理页面完美,没有包含"注册"应用程序.FYR:我使用的是python27,这是myenv的pip冻结:

> pip freeze
Django==1.9
django-registration-redux==1.2
wheel==0.24.0

和settings.py包含以下应用程序:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'registration',
]

你对这里的问题有什么想法吗?



1> issathink..:

我遇到了同样的错误(看看文档,Site是在下面django.contrib.sites.modelsRequestSite下面django.contrib.sites.requests).替换:

from django.contrib.sites.models import RequestSite

通过

from django.contrib.sites.requests import RequestSite

in [YourPath]/admin.py,(C:\Users\AdamSmith\projects\myvenv\lib\site-packages\registration\admin.py在你的情况下).



2> 小智..:

此问题已在django-registration-redux 1.3中修复.请参阅https://github.com/macropin/django-registration/issues/132.

推荐阅读
jerry613
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有