django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configur

出现这种“django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.”

情况是没有设置django环境。

解决方法如下:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ywpt.settings")  #ywpt.settings根据自己的项目来

import django
django.setup()

from facilityinfo import models 上面先加,再引入model
posted @ 2017-11-29 21:24  kennyhip  阅读(297)  评论(0)    收藏  举报