完整报错信息如下

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

经查询由于user_enterpoint.py文件和manage.py文件在同级目录下,因此在main方法里面要加入如下代码,并且在开头import那里不能导入models模块

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "crazyeyes.settings")
import django
django.setup()
import getpass,os
#from audit import models #models模块不能再此处import
from django.contrib.auth import authenticate
 

完整代码如下所示


import getpass,os
from django.contrib.auth import authenticate class UserPortal(object):
"""用户命令行端交互入口"""
def __init__(self):
pass def user_auth(self):
"""完成用户交互"""
retry_count=0
while retry_count<3:
username=input("Username").strip()
if len(username) == 0: continue
password=getpass.getpass("Password:").strip()
print("Password can not be null")
user=authenticate(username=username,password=password)
if user:
self.user=user
print("welcome login... ")
retry_count+=1
else:
exit("Too many attempts.") def interactive(self):
"""交互函数"""
self.user_auth() if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "crazyeyes.settings")
import django
django.setup()
from audit import models portal=UserPortal()
portal.interactive()

 再次执行user_enterpoint.py, 不在报错

django调用py报错 django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured.的更多相关文章

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

    Error info: django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, ...

  2. pythoncharm 中解决启动server时出现 “django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured”的错误

    背景介绍 最近,尝试着用pythoncharm 这个All-star IDE来搞一搞Django,于是乎,下载专业版,PJ等等一系列操作之后,终于得偿所愿.可以开工了. 错误 在园子里找了一篇初学者的 ...

  3. celery开启worker报错django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE o

    其实挺简单的问题,但花了自己一个下午来解决,先是浏览各种博客,无果:没办法,然后去看celery官方文档,无果,近乎绝望,最后仔细看代码,找到问题所在(如下),自学狗这效率...... 下面是自己ta ...

  4. 关于Django报错django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configure

    报错代码:django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but se ...

  5. django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)

    在python的开发中,遇到了这个错误: django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TA ...

  6. 解决:django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not 的方法

    错误类型: 该错误是在在创建Django工程时出现遇到的错误 完整报错信息:(博文标题输入长度有限制) django.core.exceptions.ImproperlyConfigured: Req ...

  7. Django--django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE

    Django序列化时遇到错误: django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESP ...

  8. django中执行py报错Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured

    https://blog.csdn.net/heybob/article/details/49684261 django代码下面直接run的时候报错: django.core.exceptions.I ...

  9. dajngo控制台添加数据报错Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured.

    报错: django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but set ...

随机推荐

  1. vue总结2

    1. 给router-link添加事件 之前用v-link 现在用 router-link 添加事件要用原生的.native修饰v-on <my-component v-on:click.nat ...

  2. sqlserver window身份验证时切换账户的快捷键

    sqlserver window身份验证时切换账户的快捷键:ctrl+alt_del

  3. 10.8H5日记

    1.网页中去滚动条的属性 overflow:hidden: overflow-x:hidden:水平超出隐藏 2.z-index 层次叠加 元素重叠 谁的值大谁就在上边 当 当前元素有float和父级 ...

  4. Android开发颜色大全

    <!-- dialog背景颜色 --> <color name=</color> <color name="white">#FFFFFF& ...

  5. Architecture.SOLID-Principles

    SOLID Principles Reference 1. Single Responsibility http://en.wikipedia.org/wiki/Single_responsibili ...

  6. POJ2230 Watchcow

    原题链接 类欧拉回路,要求每条边被正反各经过一次,且从\(1\)出发并回到\(1\). 只需每次搜索该点的边时,将该点的边对应的邻接表头及时修改为下一条即可,因为邻接表恰好储存了正反方向的边,所以及时 ...

  7. windows下git的使用方法(码云)

    这表文章主要是用了可视化操作: 使用命令行操作:https://www.cnblogs.com/mswyf/p/9370238.html 一.安装Git Bash 为了在windows下使用Git,我 ...

  8. LibreOJ #2006. 「SCOI2015」小凸玩矩阵 二分答案+二分匹配

    #2006. 「SCOI2015」小凸玩矩阵 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据   题目描述 ...

  9. A面&B面

    难难难.道是玄,不遇知音不可谈.遇了知音聊两句,免教那枉费舌尖.难得今天心情不错,反思毕业这五年的种种,有浑噩.迷茫.彷徨.莽撞.执着.困顿.不惧,走到今天迈过了几道坎早已忘却,同时也还在询问自己值不 ...

  10. Python之路(第十篇)迭代器协议、for循环机制、三元运算、列表解析式、生成器

    一.迭代器协议 a迭代的含义 迭代器即迭代的工具,那什么是迭代呢? #迭代是一个重复的过程,每次重复即一次迭代,并且每次迭代的结果都是下一次迭代的初始值 b为何要有迭代器? 对于序列类型:字符串.列表 ...