Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python NameError:未定义名称“LoginView”_Python_Django_Python 3.x_Openstack Horizon - Fatal编程技术网

Python NameError:未定义名称“LoginView”

Python NameError:未定义名称“LoginView”,python,django,python-3.x,openstack-horizon,Python,Django,Python 3.x,Openstack Horizon,我正在按照网站上的教程安装Openstack Stein Horizon服务仪表板。 由于Django版本的原因,我遇到了一个错误,并使用此解释修复了它 出现的下一个问题是AttributeError:模块'django.contrib.auth.views'没有属性'login',我在谷歌上搜索了它,再次发现它与django版本不兼容。 我在这里遵循了这个解释: openstack_auth/url.py apache2/error.log Django版本:2.2 Thks.您确实将djan

我正在按照网站上的教程安装Openstack Stein Horizon服务仪表板。 由于Django版本的原因,我遇到了一个错误,并使用此解释修复了它

出现的下一个问题是AttributeError:模块'django.contrib.auth.views'没有属性'login',我在谷歌上搜索了它,再次发现它与django版本不兼容。 我在这里遵循了这个解释:

openstack_auth/url.py

apache2/error.log

Django版本:2.2

Thks.

您确实将django.contrib.auth.views模块作为auth_视图导入,而不是从该模块导入LoginView、LogoutView等。例如,您可以使用auth_views.LoginView:

您确实将django.contrib.auth.views模块作为auth_视图导入,而不是从该模块导入LoginView、LogoutView等。例如,您可以使用auth_views.LoginView:


是的,就是这样。我错过了,非常感谢威廉。我的下一个错误是django.template.exceptions.TemplateDoesNotExist:registration/login.html,我将尝试解决它。又是Thks。@jbacelo:您在某处指定了一个模板registration/login.html,但它不存在,或者至少不在模板目录中。我没有指定任何内容,这是Openstack Horizon服务教程中的新安装,我正在修复出现的错误。是的,就是这样。我错过了,非常感谢威廉。我的下一个错误是django.template.exceptions.TemplateDoesNotExist:registration/login.html,我将尝试解决它。又是Thks。@jbacelo:您在某个地方指定了一个模板registration/login.html,但它不存在,或者至少不在模板目录中。我没有指定任何内容,这是Openstack Horizon服务教程中的新安装,我正在修复出现的错误。
from django.conf.urls import url
from django.views import generic

from openstack_auth import utils
from openstack_auth import views
from . import views
from django.contrib.auth import views as auth_views

urlpatterns = [
    url(r"^login/$", LoginView.as_view(), name='login'),
    url(r"^logout/$", LogoutView.as_view(), name='logout'),
    url(r'^switch/(?P<tenant_id>[^/]+)/$', views.switch,
        name='switch_tenants'),
    url(r'^switch_services_region/(?P<region_name>[^/]+)/$',
        views.switch_region,
        name='switch_services_region'),
    url(r'^switch_keystone_provider/(?P<keystone_provider>[^/]+)/$',
        views.switch_keystone_provider,
        name='switch_keystone_provider')
]

if utils.is_websso_enabled():
    urlpatterns += [
        url(r"^websso/$", views.websso, name='websso'),
        url(r"^error/$",
            generic.TemplateView.as_view(template_name="403.html"))
    ]
   Traceback (most recent call last):
   File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/wsgi.py", line 141, in __call__
     response = self.get_response(request)
   File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py", line 75, in get_response
     response = self._middleware_chain(request)
   File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py", line 36, in inner
     response = response_for_exception(request, exc)
   File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py", line 90, in response_for_exception
     response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
   File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py", line 128, in handle_uncaught_exception
     callback, param_dict = resolver.resolve_error_handler(500)
   File "/usr/local/lib/python3.6/dist-packages/django/urls/resolvers.py", line 584, in resolve_error_handler
     callback = getattr(self.urlconf_module, 'handler%s' % view_type, None)
   File "/usr/local/lib/python3.6/dist-packages/django/utils/functional.py", line 80, in __get__
     res = instance.__dict__[self.name] = self.func(instance)
   File "/usr/local/lib/python3.6/dist-packages/django/urls/resolvers.py", line 564, in urlconf_module
     return import_module(self.urlconf_name)
   File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
     return _bootstrap._gcd_import(name[level:], package, level)
   File "<frozen importlib._bootstrap>", line 994, in _gcd_import
   File "<frozen importlib._bootstrap>", line 971, in _find_and_load
   File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
   File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
   File "<frozen importlib._bootstrap_external>", line 678, in exec_module
   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
   File "/usr/lib/python3/dist-packages/openstack_dashboard/urls.py", line 53, in <module>
     urlpatterns.append(url(r'^auth/', include(u)))
   File "/usr/local/lib/python3.6/dist-packages/django/urls/conf.py", line 34, in include
     urlconf_module = import_module(urlconf_module)
   File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
     return _bootstrap._gcd_import(name[level:], package, level)
   File "<frozen importlib._bootstrap>", line 994, in _gcd_import
   File "<frozen importlib._bootstrap>", line 971, in _find_and_load
   File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
   File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
   File "<frozen importlib._bootstrap_external>", line 678, in exec_module
   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
   File "/usr/lib/python3/dist-packages/openstack_auth/urls.py", line 23, in <module>
     url(r"^login/$", LoginView.as_view(), name='login'),
   NameError: name 'LoginView' is not defined
from django.contrib.auth import views as auth_views

urlpatterns = [
    url(r"^login/$", auth_views.LoginView.as_view(), name='login'),
    url(r"^logout/$", auth_views.LogoutView.as_view(), name='logout'),
    url(r'^switch/(?P<tenant_id>[^/]+)/$', views.switch,
        name='switch_tenants'),
    url(r'^switch_services_region/(?P<region_name>[^/]+)/$',
        views.switch_region,
        name='switch_services_region'),
    url(r'^switch_keystone_provider/(?P<keystone_provider>[^/]+)/$',
        views.switch_keystone_provider,
        name='switch_keystone_provider')
]
from django.contrib.auth.views import LoginView, LogoutView

urlpatterns = [
    url(r"^login/$", LoginView.as_view(), name='login'),
    url(r"^logout/$", LogoutView.as_view(), name='logout'),
    url(r'^switch/(?P<tenant_id>[^/]+)/$', views.switch,
        name='switch_tenants'),
    url(r'^switch_services_region/(?P<region_name>[^/]+)/$',
        views.switch_region,
        name='switch_services_region'),
    url(r'^switch_keystone_provider/(?P<keystone_provider>[^/]+)/$',
        views.switch_keystone_provider,
        name='switch_keystone_provider')
]