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

时间:2016-07-16 00:05:35

标签: python django tastypie

我想知道是否有人可以帮我弄明白为什么我会得到一个" ImportError:无法导入名称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',
}

还有哪些其他信息有用?

2 个答案:

答案 0 :(得分:3)

从版本1.9开始,{django中删除了same_origin方法。你可以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个文件,请务必同时更新其中的版本号。

答案 1 :(得分:1)

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

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