【问题标题】:Import Error : No module named django_orm导入错误:没有名为 django_orm 的模块
【发布时间】:2016-07-18 23:40:44
【问题描述】:

oauth2client.django_orm 导入 CredentialsField 时,我得到:

Import Error: No module named django_orm

我已经安装了先决条件:django-ormpython-oauth2

【问题讨论】:

  • 您需要在帖子中添加跟踪/实际错误
  • 需要在settings.py的INSTALLED_APPS中添加django_orm

标签: python python-2.7 django-1.9


【解决方案1】:

Drive API Guide 上的文档不是最新的(最后更新于 2015 年 5 月)。

改用这些导入:

from oauth2client.contrib.django_orm import CredentialsField
from oauth2client.contrib.django_orm import FlowField
from oauth2client.contrib.django_orm import Storage

如果您遵循 API 指南,那么更多的导入将会中断。 oauth2client 的开发者已将所有非核心模块(django_orm、xsrfutil、appengine 等)移至contrib。如果您有更多ImportErrors,请参考oauth2client source code

【讨论】:

    【解决方案2】:

    OAuth2 库似乎发生了变化:

    将所有与 django 相关的代码重构为 oauth2client.contrib.django_util。添加 DjangoORMStorage,删除 流场。 (#546)

    你可以查看这个here

    也许你可以尝试这样的事情(运行它时我没有收到任何导入错误,但我不确定它是否有效):

    from oauth2client.contrib.django_util.storage import DjangoORMStorage
    from oauth2client.contrib.django_util.models import CredentialsField
    

    【讨论】:

    • 只是一个更新,我已经尝试过了,它似乎工作正常。我可以将凭据保存在 CredentialsField 上并使用 DjangoORMStorage 检索它。
    【解决方案3】:

    看起来 oauth2client 库已被弃用。查看更多最新的google-authhttps://google-auth.readthedocs.io

    使用身份验证令牌创建凭据对象:https://google-auth.readthedocs.io/en/latest/user-guide.html#user-credentials

    import google.oauth2.credentials
    
    credentials = google.oauth2.credentials.Credentials(
        'access_token')
    

    【讨论】:

      猜你喜欢
      • 2018-07-10
      • 2015-11-30
      • 2012-05-25
      • 2012-03-16
      • 2011-12-10
      • 2018-07-06
      • 1970-01-01
      • 2019-07-20
      相关资源
      最近更新 更多