我有一个文件:
def fetchArticles(topic):
testing()
def testing():
print("testing")
print("starting")
fetchArticles("World")
它存在于django中的应用程序中,当我使用python3 xyz.py将其作为独立文件运行时,它运行完全正常但是当我使用python3 manage.py shell< django shell运行它时xyz.py它无法找到测试功能。
显示此错误:
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
有人可以帮我解决这个问题吗?