我有一个文件:
def fetchArticles(topic):
testing()
def testing():
print("testing")
print("starting")
fetchArticles("World")
它存在于 django 的应用程序中,当我使用 python3 xyz.py 作为独立文件运行它时,它运行得非常好,但是当我使用 python3 manage.py shell < xyz.py 在 django shell 中运行它时,它无法找到测试功能。
它显示此错误:
starting
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/commands/shell.py", line 101, in handle
exec(sys.stdin.read())
File "<string>", line 12, in <module>
File "<string>", line 4, in fetchArticles
NameError: name 'testing' is not defined
谁能帮我解决这个问题?