[英]ImportError: cannot import name social_auth_usersocialauth: Accessing Python social auth data in django via shell
我正在從Twitter獲取登錄數據。 在我的sqlite數據庫中,下表是:
sqlite> .tables
auth_group django_content_type
auth_group_permissions django_migrations
auth_permission django_session
auth_user social_auth_association
auth_user_groups social_auth_code
auth_user_user_permissions social_auth_nonce
django_admin_log social_auth_usersocialauth
我的數據已保存到social_auth_usersocialauth
表中。 使用sqlite3 shell查詢表會給我我從網站上獲取的數據。
1|twitter|xx|1|{"access_token": {"oauth_token_secret": "xx", "oauth_token": "xx", "x_auth_expires": "0", "user_id": "xx", "screen_name": "xx"}, "id": xx}
現在,我想在模板中顯示oauth_token_secret
和oauth_token
。
我正在嘗試從Django shell運行以下查詢,以檢查是否可以獲取數據。 由於我的應用程序名稱為social.apps.django_app.default
因此我運行了以下代碼:
>>> from social.apps.django_app.default.models import social_auth_usersocialauth
但它給
Traceback (most recent call last): File "<console>", line 1, in <module> ImportError: cannot import name social_auth_usersocialauth
嘗試使用另一個名字twitter
(這是我的應用程序名稱),我得到了同樣的東西。
模型導入肯定有問題
模型是否在models.py文件中? 如果是這樣,您寫的內容是否匹配? 發布models.py文件和文件夾結構。
該應用名稱實際上是social.apps.django_app ...
通常,Django項目的結構是這樣的
項目名稱-應用程序名稱--- models.py-應用程序名稱...
然后,Django shell中的引用來自appname.models import modelname
然后,Django將命名數據庫表Appname_modelname
@lerner:您必須正確導入表名。 嘗試在python shell中運行此import語句
from social.apps.django_app.default.models import UserSocialAuth
希望您現在可以通過查詢該表來訪問表內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.