无法导入''。路径必须完全合格

时间:2018-05-16 17:36:52

标签: python django import

我正在与Django合作几个月并建立这个网站只是为了好玩和进一步提高自己,我不能为我的生活摆脱这个错误,我已经找了我所有的代码,不能找到这个导入错误,由于某种原因,它不会告诉它出错的地方。这是错误。然而,奇怪的是,这并不总是发生在这个页面上,就像他们轮流错误一样,例如,我能够在没有任何问题的情况下登录,但有时候,我得到这个错误,所有我要做的只是重新加载页面并再次输入我的详细信息。

Environment:

Request Method: POST
Request URL: https://www.enfieldgrammar.tk/account/login/?next=/account/

Django Version: 1.11b1
Python Version: 3.6.0
Installed Applications:
['accounts',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)

File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py" in _legacy_get_response
  249.             response = self._get_response(request)

File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py" in _get_response
  178.             response = middleware_method(request, callback, callback_args, callback_kwargs)

File "/usr/local/lib/python3.6/dist-packages/django/middleware/csrf.py" in process_view
  314.                 return self._reject(request, REASON_BAD_TOKEN)

File "/usr/local/lib/python3.6/dist-packages/django/middleware/csrf.py" in _reject
  163.         return _get_failure_view()(request, reason=reason)

File "/usr/local/lib/python3.6/dist-packages/django/middleware/csrf.py" in _get_failure_view
  43.     return get_callable(settings.CSRF_FAILURE_VIEW)

File "/usr/local/lib/python3.6/dist-packages/django/urls/utils.py" in get_callable
  27.         raise ImportError("Could not import '%s'. The path must be fully qualified." % lookup_view)

Exception Type: ImportError at /account/login/
Exception Value: Could not import ''. The path must be fully qualified.

1 个答案:

答案 0 :(得分:0)

从堆栈跟踪的外观来看,这里发生了什么:

  • 您正在向Django发送HTTP POST请求
  • 您安装了CSRF Middleware;这是件好事。在此处阅读有关CSRF的更多信息。
  • POST请求没有CSRF令牌,这会在Django中引发错误。
  • Django正试图向您展示为CSRF失败显示的默认视图。这由settings.CSRF_FAILURE_VIEW - >控制。默认为django.views.csrf.csrf_failure,记录为here
  • 然而,Django似乎正在寻找一个空字符串''
  • 的视图

基于此,您的项目设置似乎将settings.CSRF_FAILURE_VIEW的值设置为空字符串'' - >如何以及在何处发生这是您需要进一步调试的内容。

我的猜测是使用某种包装器从环境中获取setting个变量,并回退到空字符串'',这将覆盖Django的默认回退到django.views.csrf.csrf_failure