2011-12-07 81 views
0

我想设置一个Cron作业来运行django文件。Django的Cron作业文件

我想知道的是django-cron是一个很好的选择吗?或者还有其他可以使用的应用程序吗? 如果不是,如何通过命令行运行django文件?

[email protected] ~/workspace/bolt (master) 
$ python ./log/cron.py 
Traceback (most recent call last): 
    File "./log/cron.py", line 3, in <module> 
    from account.models import UserProfile 
ImportError: No module named account.models 

我已经设置了以下变量

[email protected] ~/workspace/bolt (master) 
$ export DJANGO_SETTINGS_MODULE=settings 

我不断收到这些错误正在引用的文件有直接进口

from foo.models import * 

任何帮助将得到高度赞赏。

自定义命令

from django.core.management.base import BaseCommand, CommandError 
import pdb 
import datetime 

from too.models import UserProfile 
from foo.api import end_all_foo_conversations 


class Command(BaseCommand): 
    # in minutes 
    def handle(self,*args,**options): 
     print datetime 

试图运行命令,我得到的错误如下: -

'queryset': self.rel.to._default_manager.using(db).complex_fi 

imit_choices_to), AttributeError的: '海峡' 对象有没有属性' _default_manager'

回答

1

我想你应该写一个custom management command并通过manage.py运行它。

+0

请检查我的编辑 – Akamad007

+0

@AkashDeshpande你的命令看起来很好,在什么文件中引发这个错误? – DrTyrsa

+0

当我通过命令行运行命令时出现此错误 – Akamad007