2017-09-05 18 views
0

我想設置爲JWT令牌保質期添加JWT_AUTH,所以我加了這對settings.py無法在設定

JWT_AUTH = { 
    'JWT_EXPIRATION_DELTA': datetime.timedelta(days=30), 
} 

一旦我添加它的設置,我得到這個錯誤

django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS. 

'JWT_AUTH'有什麼問題? settings.py

INSTALLED_APPS = [ 
    'corsheaders', 
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    'django.contrib.sites', 
    'allauth', 
    'allauth.account', 
    'rest_auth.registration', 
    'rest_framework', 
    'rest_framework.authtoken', 
    'rest_auth', 
    'profiles', 
    'allauth.socialaccount', 
    'allauth.socialaccount.providers.facebook', 
] 
# localhost:8000/ 
SITE_ID = 9 
+0

網址正在調用導入尚未加載的網站框架的視圖。只有候選人是corsheaders,但我不明白這是如何與添加JWT_AUTH字典配合。 – Melvyn

+0

嗯..好吧,我把corsheaders放在'django.contrib.sites'後面。但它也沒有效果。我想你找到了問題所在。 –

+1

您是否也按照[認證後端說明](https://getblimp.github.io/django-rest-framework-jwt/)? – Melvyn

回答

1

的這些相關部件因此很明顯,在網站模型誤差settings.py結果任何未解決的引用,沒有名字settings.py中的錯誤。

雖然這並不在股票的Django(python manage.py check)發生:

'foo': datetime.timedelta(days=3),

NameError: name 'datetime' is not defined

DRF確實有一些設置忙玲,可能導致此行爲。