What is a good way to run Background Tasks in Django for building Report and sending an email later?

There are some requirements as the following detail, I am supposed that it should be executed by running a background task process in Django because It will take some time to do it. If I really want to do like that.

What is a good way to run Background Tasks in Django for building Report and sending an email later?

  1. User request buiding report on a web page.
    Once clicked “Build Excel Report” button, This request is sent to the Django web site and a return message to inform the user that “Already accepted your request and we will send a report to your email later.”
    and finished the task

  1. After that, Django will sent the command to the python script responsible for creating a report in that as a background task. It will probably take some time to do it .
    This python script can be a script in Django folder or outside or script that has been set in the window task scheduler.

If the process complete then The scrip will send the report through email, including the attached report file.

I found some articles as below but not sure whether they are suitable for this my requirement or not.

It seems like that is Supported versions and compatibility
Python: 2.7, 3.4-3.7
Django: 1.8, 1.11, 2.1, 2.2
But my environment is python 3.8 and Django 3.1

This link looks interesting but seems complicated to configure. It uses celery, redis

Anyone can share Any ideas with me .
Thank you

You can implement Celery without Redis, and in your case I think Redis would be overkill. TBH, Celery may be overkill as well -it’s a big package, but it would certainly do the job you want. There’s also a package called Django Q, which I think is tested with Django 3.1

1 Like

We use Celery a lot for what we do - once you get past the initial learning curve (IMO, not very steep relative to Django overall), it’s really easy to work with. Celery does require some kind of “broker” between your celery tasks and Django. We used to use RabbitMQ as a broker but switched to Redis because it’s a easier to install, configure (no configuration in the simple case), and use.
If you have a high-Celery utilization site where you wish to prioritize traffic and use multiple client systems running different tasks, RabbitMQ has a number of features to make that type of situation easier to manage. But redis is definitely the simpler solution there.

1 Like

Thank you for your good advice.
I will try to implement it in the next week.

Thank you for your good advice.
I suppose that my case is not complicated too much.
I 'm going to try both Django Q and Celery.

I’ve also heard good things about Huey. I believe it’s what the team over at Real Python uses (IIRC from an interview that I heard with Dan Bader in the past).

Thank you.
It seems there are a lot of tools to implement based on my issue.

I will try it out.

Is it ok?

That’s what we use. (Actually, I think our most recent deployment is still on 4.4.x, but I’d feel comfortable with a version 5 deployment. It’s a very mature and stable product.)

1 Like

I have an additional question.
Assuming, my Django has been deployed on Window.
I have the other python script file that has been set as Window Task Scheduler.
It runs for doing something on a daily basis

if I want to run manually but run via clicking a button on the web
Is it possible for me if we can send a command toward the Django web site to run Window Task Scheduler?

If you can write a Python script that will run your desired script, you can do it from within a view. (A view is “just” a python script that receives a request and returns a response. What that view does in between those two things is entirely up to you.)

I understand that I write a python script in view.
I am looking for a script in order to run window task scheduler with view.py
I haven’t seen code sample.

That’s a Python on Windows issue, not a Django issue. You’ll want to look at some of the resources available for Python.



I really appreciate your help.

I have a problem close to yours.
How have you solved your problem?

If you can provide some tips, I would appreciate!