python - Django文件从shell运行但不运行但自己运行
问题描述
尝试在我的项目中运行文件时,出现错误:
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
但是,当运行python3 manage.py shell
代码并将其粘贴到 shell 中时,它可以正常工作。
该文件如下所示:
from models import *
products = Product.objects.all()
iterable_form = []
for p in products:
a = []
a.append(p.ID)
a.append(p.title)
a.append(p.official_path_name)
a.append(p.quantity)
a.append(p.language)
a.append(p.book_type)
a.append(p.authorID)
a.append(p.editionID)
iterable_form.append(a)
print(iterable_form)
解决方案
推荐阅读
- python-3.x - 递归调用中返回后调用 Else 语句
- mysql - 获取用逗号分隔的值的计数
- python - 使用 python + requests 从链接下载多个 zip 文件
- reactjs - Next.js 禁用文件系统路由
- python - URI 下的 flask-admin 会断开指向视图的链接
- r - 在闪亮的应用程序中缓存或预渲染传单地图
- amazon-web-services - 如何在kibana的索引中正确嵌套映射?
- express - 提供图像文件夹的最佳方式是什么?快递服务器
- amazon-web-services - 将视频上传到 .net 中的 AWS S3
- html - 使用 CSS 参数化文本的长度