我看过这篇关于如何从django运行python脚本的帖子:http://www.djangotutsme.com/how-to-run-python-script-from-django/
我尝试了这个示例,但在运行python manage.py runscript myscript
时遇到以下错误。
我安装了Python 2.7,Django 1.10和django扩展1.6.1。
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib/python2.7/site-packages/Django-1.10.dev20151201151517-py2.7.egg/django/core/management/__init__.py", line 349, in execute_from_command_line
utility.execute()
File "/usr/lib/python2.7/site-packages/Django-1.10.dev20151201151517-py2.7.egg/django/core/management/__init__.py", line 341, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.7/site-packages/Django-1.10.dev20151201151517-py2.7.egg/django/core/management/__init__.py", line 193, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/lib/python2.7/site-packages/Django-1.10.dev20151201151517-py2.7.egg/django/core/management/__init__.py", line 40, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/lib/python2.7/site-packages/django_extensions-1.6.1-py2.7.egg/django_extensions/management/commands/runscript.py", line 6, in <module>
from django_extensions.management.email_notifications import \
File "/usr/lib/python2.7/site-packages/django_extensions-1.6.1-py2.7.egg/django_extensions/management/email_notifications.py", line 10, in <module>
class EmailNotificationCommand(BaseCommand):
File "/usr/lib/python2.7/site-packages/django_extensions-1.6.1-py2.7.egg/django_extensions/management/email_notifications.py", line 49, in EmailNotificationCommand
**option_list = BaseCommand.option_list + (
AttributeError: type object 'BaseCommand' has no attribute 'option_list'**
知道问题是什么吗?这是django中的一个错误吗?
答案 0 :(得分:9)
BaseCommand.option_list
在Django 1.8中已弃用,在Django 1.10中已删除。它看起来像Django-extensions has been updated,但从那以后就没有新版本。
您可以尝试从主分支安装django-extensions,但最好使用最新版本的Django,目前为1.9.2。 Django 1.10尚未发布,目前仍处于开发阶段。