无法从 authentication.py tastypie django 导入名称 same_origin

cannot import name same_origin from authentication.py tastypie django

我想知道是否有人可以帮我弄清楚为什么我会收到 "ImportError: cannot import name same_origin"

这是完整的堆栈跟踪:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 353, in execute_from
_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 398, in execute
    self.check()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 426, in check
    include_deployment_checks=include_deployment_checks,

  File "/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py", line 75, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 23, in check_resolver
    for pattern in resolver.url_patterns:
  File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 417, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 33, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 410, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
File "/var/www/will/agora/agora/urls.py", line 6, in <module>
    from bin.resources import QuestionResourse, UserResource, ResponseResourse
  File "/var/www/will/agora/bin/resources.py", line 1, in <module>
    from tastypie.resources import ModelResource
  File "/usr/local/lib/python2.7/dist-packages/django_tastypie-0.12.2-py2.7.egg/tastypie/resources.py", line
20, in <module>
    from tastypie.authentication import Authentication
  File "/usr/local/lib/python2.7/dist-packages/django_tastypie-0.12.2-py2.7.egg/tastypie/authentication.py",
line 11, in <module>
    from django.utils.http import same_origin
ImportError: cannot import name same_origin

我安装的应用程序:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'bin',
    'tastypie',
}

还有哪些有用的信息?

django.utils.http 没有 same_origin 函数 (https://docs.djangoproject.com/en/1.9/ref/utils/)

也许这就是您要找的? https://docs.djangoproject.com/en/1.9/ref/clickjacking/

从 1.9 版开始,same_origin 方法已从 django 中删除。你可以 look at the commit here.

这似乎已在 tastypie 中修复 as of v0.13.0

此外,tastypie v0.12 不支持 django 1.9,but v0.13 does。通过 运行 升级 tastypie:

$ pip install django-tastypie==0.13.3 

如果您有 requirements.txt 文件,请务必同时更新版本号。