完整报错信息如下

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. java遍历当前会话所有Session

    //方法一:通过遍历的方法进行遍历 String FileName=""; HttpSession session=request.getSession();//获取session ...

  2. ubuntu下sudo apt-get update Sources 404 Not Found 解决方法

    刚安装了ubuntu之后的主要安装命令无非就是apt-get install了,然而很多都在这里就夭折了. 使用apt-get install ***需要先执行apt-get update 加载文件包 ...

  3. ADT和DS

    Abstract Data Type vs. Data Structrue 抽象数据类型=数据模型+定义在该模型上的一组操作.  interface 数据结构=基于某种特定语言,实现ADT的一整套算法 ...

  4. appium 问题

    adb shell pm list packages:列出所有的包名.adb shell dumpsys package:列出所有的安装应用的信息dumpsys package com.android ...

  5. Cloud Foundry v2 部署及入门运维

    之前写过一个Guide for Cloud Foundry New Teamer.不过似乎已经有些过时,那会实验室主要是针对的CF v1进行的研究,现在已经全面进入V2时代了.所以更新一下关于Clou ...

  6. mysqldump 导出数据库各参数详细说明

    mysqldump是mysql用于转存储数据库的实用程序.它主要产生一个SQL脚本,其中包含从头重新创建数据库所必需的命令CREATE TABLE INSERT等. 下面我们详细介绍一下mysqldu ...

  7. go语言中container容器数据结构heap、list、ring

    heap堆的使用: package main import ( "container/heap" "fmt" ) type IntHeap []int //我们 ...

  8. Oracle_SQL(5) 连接和子查询

    一.连接join一般分类: inner join: 内连接,又叫等值连接,只返回两个表中连接字段相等的行. left join :左连接,返回左表中所有的记录以及右表中连接字段相等的记录. right ...

  9. Liunx history

    Linux中history历史命令使用方法详解   (转) 作者:青藤园来源:|2012-05-10 10:     http://os.51cto.com/art/201205/335040.htm ...

  10. iis日志分析软件及大文本切割软件下载

    在网上找了好几个日志分析软件,觉得这个是最简单.实用的,至少对我来说. 但这个软件有个缺点,就是日志比较大时,分析详细的会溢出,需要用到文本切割工具. 软件下载: iis日志分析软件 大文本切割软件 ...