2011-12-07 63 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