我想每小時向我的用戶發送推送通知。PythonAnywhere計劃任務導入錯誤
from push_notifications.models import APNSDevice
print('test schedule task')
device = APNSDevice.objects.all()
if device is None:
print('None Device')
print('number of models is '+str(len(device)))
device.send_message('test')
以上是我嘗試每小時執行一次。
但執行的腳本時,我得到一個錯誤信息:
"Traceback (most recent call last): File "/home/User/Folder/Project/App/schedule.py", line 1, in from push_notifications.models import APNSDevice ImportError: No module named push_notifications.models
2016-03-19 05:49:05 -- Completed task, took 0.00 seconds, return code was 1."
我應該怎麼做才能解決這個問題呢?
打印(sys.path中))低於:
['/home/User/Folder/Project/App', '/usr/local/lib/python2.7/dist-packages/snappy-2.3.2-py2.7-linux-x86_64.egg', '/usr/local/lib/python2.7/dist-packages/cypari-1.2.2-py2.7-linux-x86_64.egg', '/usr/local/lib/python2.7/dist-packages/pypng-0.0.18-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/FXrays-1.3.1-py2.7-linux-x86_64.egg', '/usr/local/lib/python2.7/dist-packages/spherogram-1.4.1-py2.7-linux-x86_64.egg', '/usr/local/lib/python2.7/dist-packages/plink-1.8-py2.7.egg', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/local/lib/python2.7/dist-packages/Orange/orng', '/usr/local/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode']
你確定'push_notifications'已安裝嗎? –
@ SeanFrancisN.Ballais當然,我確實成功地實現了這個功能,但是使用了計劃任務。 – LKM
'/ home/User/Folder/Project/App/push_notifications /'裏面的文件'models.py'?如果這是Django,我希望它在'/ home/User/Folder/Project/push_notifications /'中,在這種情況下,您需要將'/ home/User/Folder/Project /'添加到'sys .path'。 –