【发布时间】:2021-06-16 11:47:00
【问题描述】:
我正在为我的 Django 项目编写一些 python 脚本。我正在使用 manage.py 和 shell 运行它。
如果我使用 manage.py 运行 import json 并出售它,则它不起作用。
但是,如果我尝试不使用 shell 和 manage.py,它会起作用。我不知道为什么会这样。
使用 manage.py 和 shell:(不工作)
python3 manage.py shell < custom_scripts/imports.py
Error: NameError: name 'json' is not defined
没有 manage.py 和 shell:(有效)
python3 custom_scripts/imports.py
脚本内的代码:
import json
print(json.loads("{}"))
有什么想法吗?
【问题讨论】:
标签: python python-3.x django django-manage.py