0
0
Djangoframework~30 mins

Defining tasks in Django - Mini Project: Build & Apply

Choose your learning style9 modes available
Defining Tasks in Django
📖 Scenario: You are building a Django project that needs to perform background tasks. To do this, you will define a simple task function that can be called later by a task runner.
🎯 Goal: Create a Django task function named send_reminder_email that accepts a user_email parameter and prints a message simulating sending an email.
📋 What You'll Learn
Create a Python function named send_reminder_email in a file called tasks.py inside a Django app.
The function must accept one parameter called user_email.
Inside the function, write a print statement that outputs exactly: Sending reminder email to {user_email} using an f-string.
Ensure the function is properly defined with def syntax.
💡 Why This Matters
🌍 Real World
Background tasks like sending reminder emails are common in web applications to improve user engagement without slowing down the main app.
💼 Career
Knowing how to define and use tasks in Django is essential for backend developers working on scalable and responsive web applications.
Progress0 / 4 steps
1
Create the tasks.py file and define the function
Create a file named tasks.py inside your Django app folder. Inside it, define a function called send_reminder_email that takes one parameter named user_email.
Django
Need a hint?

Use the def keyword to define the function with the exact name and parameter.

2
Add a print statement inside the function
Inside the send_reminder_email function, add a print statement that outputs Sending reminder email to {user_email} using an f-string exactly as shown.
Django
Need a hint?

Use print(f"Sending reminder email to {user_email}") inside the function body.

3
Import the task function in views.py
In your Django app's views.py file, import the send_reminder_email function from the tasks module.
Django
Need a hint?

Use from .tasks import send_reminder_email to import the function.

4
Call the task function in a view
Inside a Django view function named reminder_view in views.py, call the send_reminder_email function with the argument "user@example.com".
Django
Need a hint?

Define reminder_view with request parameter and call send_reminder_email("user@example.com") inside it.