Schedule task in Django

Hi everyone,
I am trying to schedule a sending function in Django so in views.py I wrote this function
but I have a problem that the application stop running and only did the SendingEmail function?

import schedule
import time
def SendingEmail():
    print('ok message')
schedule.every(5).minutes.do(SendingEmail)
while 1:
    schedule.run_pending()
    time.sleep(1)

is there a way to do this without affecting the application(easy and fast)?

All my best

You need to set up an external task to do this.

You can either use something like Celery Beats or a Cron task to run a custom management command.

Either way, this sort of task is run external to the regular Django process.

3 Likes