Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
django - ajax - call python function from jquery/ajax
I'm working with Django to create a small website. in this project, I have some DateTime fields. I would use ajax (via another button) to set up the UTC date keeping in mind the solar time and daylight saving time. I created a python function which computes the hour shift. I would recall that function in the ajax code. How can I do it? -
Trying to run code in Google Cloud, getting Server 502 when accessing Django
I'm building a simple login page. You can log in using a Django account, or using Google Sign-In. I am trying to verify that you can log in using a Django account first. It deploys correctly, and I can access the site properly. But when I access Django /admin and key in the login credentials, aside from the fact that loading takes forever, I keep getting Server 502 Bad Gateway The documentations only vaguely mentions all the way at the bottom that app.yaml might be configured incorrectly but I'm not experienced enough to tell which part isnt. # [START runtime] runtime: python env: flex entrypoint: gunicorn -b :$PORT [myproject.wsgi] beta_settings: cloud_sql_instances: [instance]:asia-east2:[project] automatic_scaling: min_num_instances: 1 max_num_instances: 1 max_concurrent_requests: 80 resources: cpu: 1 memory_gb: 0.5 disk_size_gb: 10 runtime_config: python_version: 3 # [END runtime] -
After I pull a dockerized django project from the hub, how should I run it? I used docker compose
I am working on docker for the first time. I created a docker container of a Django application using docker-compose. Furthermore, I pushed the image to hub. Now, how should I run the image after pulling it back? What commands should I use? Where will the "docker-compose up" command go? -
Bad gateway when deploying Django app with awsebcli
I was using this AWS guidelines to deploy Django application to AWS EB using awsebcli. Deploying a Django application to Elastic Beanstalk But after I finished all the steps i got "502 Bad Gateway" error and I don't see any environment created in AWS console, but when I run eb status it looks like environment was created. eb status Environment details for: django-test-env Application name: django-test Region: us-west-2 Deployed Version: app-210819_194308 Environment ID: e-2h9nu62f8t Platform: arn:aws:elasticbeanstalk:us-west-2::platform/Python 3.8 running on 64bit Amazon Linux 2/3.3.4 Tier: WebServer-Standard-1.0 CNAME: django-test-env.eba-3i3hqgjc.us-west-2.elasticbeanstalk.com Updated: 2021-08-19 18:43:34.097000+00:00 Status: Ready Health: Red The only thing I did different was that I used Python 3.8 at Deploy your site with the EB CLI Step 1. Also I had to create access key ID and secret access key, to be able to login to awsebcli. -
Heroku: user status banned from creating email addons on apps
I deployed a Django application on Heroku, which uses email verification during signup. I wanted to use Sendgrid addons, unfortunately I am getting this error: Item could not be created.... **User- user status banned** -
DJANGO - Display currently logged in users count
I need help with returning number of currently logged in users to my template in django. def get_context_data(self, **kwargs): ago5m = timezone.now() - timezone.timedelta(minutes=10) active_users = Profile.objects.filter(login_time__gte=ago5m).count() context = super().get_context_data(**kwargs) context.update({ 'active_users': active_users, }) return context I have tried using the attached code as a method within my class-based view in my project but it counts each authenticated user and decrements the count after 10 minutes (Note also: when I remove the timedelta value of 10, the code doesn't even count the authenticated users at all). how can I fix this problem? Note: "login_time" is declared in my models.py file as follows: -login_time = models.DateTimeField(auto_now=True, null=True) -
How to convert pandas datetime64 into something that can be recognized as DateField by Django?
When I load an Excel using pandas, the column containing dates was correctly identified as datetime64 excel_table = pd.read_excel(path, sheet_name=ws_name, header=2) print(excel_table['Start Date']) # output: 0 2001-01-31 1 2001-03-02 2 2001-07-23 3 2001-07-25 4 2002-03-11 ... Name: Start Date, Length: 11056, dtype: datetime64[ns] Then, I wrote excel_table to a sqlite3 database: excel_table.to_sql(table_name, cols_to_use, index=False) When I inspect the columns using PRAGMA table_info(TABLENAME), I got this: ... 11|Start Date|NUM|0||0 ... Shouldn't it be TIMESTAMP rather than NUM? Then, I generate a model class using Django's inspectdb method that gave me this: # This is an auto-generated Django model module. # You'll have to do the following manually to clean this up: # * Rearrange models' order # * Make sure each model has one field with primary_key=True # * Make sure each ForeignKey and OneToOneField has `on_delete` set to the desired behavior # * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table # Feel free to rename the models, but don't rename db_table values or field names. from django.db import models class TableName(models.Model): start_date = models.TextField(db_column='Start Date', blank=True, null=True) # Field name made lowercase. Field renamed to remove unsuitable characters. This … -
Amount of queries to database in Views using Django
My question is regarding best practices for querying a database in a View using Django. I want a daily count of reservations for the past 7 days. Is it okay to have something like this? (below) count_day_1 = len(Reservations.objects.filter(date=TODAY_DATE).filter(is_reserved=True)) count_day_2 = len(Reservations.objects.filter(date=DATE_TODAY_MINUS_1).filter(is_reserved=True)) count_day_3 = len(Reservations.objects.filter(date=DATE_TODAY_MINUS_2).filter(is_reserved=True)) count_day_4 = len(Reservations.objects.filter(date=DATE_TODAY_MINUS_3).filter(is_reserved=True)) count_day_5 = len(Reservations.objects.filter(date=DATE_TODAY_MINUS_4).filter(is_reserved=True)) count_day_6 = len(Reservations.objects.filter(date=DATE_TODAY_MINUS_5).filter(is_reserved=True)) count_day_7 = len(Reservations.objects.filter(date=DATE_TODAY_MINUS_6).filter(is_reserved=True)) Or does having that Reservations.objects.filter() in there 7 times ping the database 7 times? If the above way isn't recommended, should I set it up something like this instead? (below) data = Reservations.objects.filter(is_reserved=True) for item in data: if item.date == TODAY_DATE: print(item.date) if item.date == DATE_TODAY_MINUS_1: print(item.date) (...so on and so forth) Any advice would be great. Thanks! -
How to filter an object witch has one of the two foreign key relation in Django one to many relationship
I have city and routes models class City(LocationAbstractModel): name = models.CharField(max_length=255) def __str__(self): return self.name class Route(BusAbstractModel): leaving_from = models.ForeignKey(location_models.City, on_delete=models.CASCADE, related_name='leaving_from') destination = models.ForeignKey(location_models.City, on_delete=models.CASCADE, related_name='destination') distance = models.IntegerField(null=True, blank=True) prices = models.ManyToManyField(carrier_models.Carrier, through="RoutePrice") crossing_cities = models.ManyToManyField(location_models.City, blank=True) def price(self, carrier_id): return self.routeprice_set.filter(carrier_id=carrier_id).order_by('created_at').first().price def __str__(self): return self.leaving_from.name + " -> " + self.destination.name How can I query only cities which has one of the relation in routes model. I want to filter cities which has either leaving_from or destination relation ship. I have tried models.City.objects.filter(Q(route__leaving_from__isnull=False) |Q(route__destination__isnull=False)).distinct() but it is only returning cities which has relation on both leaving_from and destination. How can I Filter Cities which has one of the relationships -
django fails to install psycopg2
I'm running Django 3.2 (Python 3.8.2) in a virtual environment on my Windows 10 PC and I'm trying to install psycopg2. I've successfully used postgresql and psycopg2 on this PC before, in a different virtual environment. However, this time I'm getting errors. I've tried: pipenv install psycopg2-binary==2.9.1 pipenv install psycopg2==2.9.1 pipenv install psycopg2 Each attempt ends with the error: raise InstallationError( pipenv.patched.notpip._internal.exceptions.InstallationError: Command "python setup.py egg_info" failed with error code 1 in C:\Users\...\psycopg2... -
Choosing a Main Image in a Foreign Key
I have the following two models: class Event(models.Model): title = models.CharField(max_length=250) description = RichTextField() start_date = models.DateField() start_time = models.TimeField() end_date = models.DateField(blank=True, null=True) end_time = models.TimeField(blank=True, null=True) location = models.CharField(max_length=100) volunteers = models.PositiveIntegerField(default=0) sdgs = models.ManyToManyField(SDG) def __str__(self): return f'{self.title}' class EventPhoto(models.Model): event = models.ForeignKey(Event, on_delete=models.CASCADE) photo = models.ImageField(upload_to='events/photos') A single Event object can contain multiple photos, maybe 1, maybe 10 or maybe 100. I am using the following code inside of my admin.py file. class EventPhotosInline(admin.StackedInline): model = EventPhotos @admin.register(Event) class EventAdmin(admin.ModelAdmin): inlines = [EventPhotosInline,] The above code allows me to add EventPhoto objects while I am adding a new event in the admin dashboard. My question is, how would I go about choosing on of the many photos to be the main photo of the event? I could of easily created an image field inside the Event model with the name main_photo, but in the future if I have to change the main photo I have to upload a new one, all I need is to just use one of the many uploaded images as my main photo. How would I go about creating something similar to what I want?! I also tried adding a boolean field … -
Django: How to solve several Foreign key relationship problem?
I'm currently learning Django and making electronic grade book. I am completely stuck after trying everything, but still cannot solve the problem. I will explain in detail and post all the relevant code below. I need to have two url pages "class_students" and "teacher_current". The first page is for the teacher to see the list of students of a certain class. The table on this page has "action" column. In every cell of this column there is View button, so that the teacher could be redirected to "teacher_current" page and see the list of current tasks, given to a certain student. On this page there is a "Mark" column, its cells may contain EITHER mark given to this student with link to another page to update or delete this mark OR "Add mark" link to add mark on another page. Here comes the problem: everything works correctly, except the thing that each mark is related to a Task class via Foreign key and NOT to a Student class. So every student of the same class has the same marks for the same tasks. But it certainly won't do. Here is all my relevant code: 1) views.py models.py urls.py: https://www.codepile.net/pile/qkLKxx6g 2) … -
show list in django without html file?
i have 2 models but i want to show name of artist in my output class Musician(models.Model): name = models.CharField(max_length=50) instrument = models.CharField(max_length=100) class Album(models.Model): name = models.CharField(max_length=100) artist = models.ForeignKey(Musician, on_delete=models.CASCADE) num_stars = models.IntegerField() i want to show musician name by HttpResponce funcction class Musician_list(Musician ,Album ): def get(self, request): qury= Musician.objects.all().values_list("name").order_by("name") return HttpResponse(qury) but this code dont show any things please help me. -
CORS Issues after adding headers field to axios when making a GET request
I am using Django REST for my API/Back end. Here is my python code: MIDDLEWARE = [ 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', #'corsheaders.middleware.CorsPostCsrfMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] CORS_ALLOWED_ORIGINS = [ "http://localhost:3000", "http://127.0.0.1:3000" ] CORS_ORIGIN_WHITELIST = [ "http://localhost:3000", "http://127.0.0.1:3000" ] On my React JS front end: listItems = async () =>{ let fetchedItems = await axios.get("http://localhost:8000/api/shipments/list/", {headers: {accessToken: this.props.token, "Access-Control-Allow-Headers" : '*'}}); } I did not get any CORS errors when I had listItems without the headers part: listItems = async () =>{ let fetchedItems = await axios.get("http://localhost:8000/api/items/list/"}); } However, I need to pass the accessToken in the request's header. Here is the error that I am getting: Access to XMLHttpRequest at 'http://localhost:8000/api/items/list/' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field accesstoken is not allowed by Access-Control-Allow-Headers in preflight response. What is the reason behind having such CORS issues, what's the best way to fix it ? -
Remove templates from Django
We are using Django solely as backend and not utilizing its template system while we are developing our code. Current set up that we have points templates to the folder where our front end is located in dist/ui. Maybe in production mode when we could build actual combined binaries and want to serve them from the server it could be useful but in the development mode it often causes issues when there are some inconsistencies in the dist/ui folder with the folder structure of the development folder. Is it possible to avoid that behavior? How could we prevent Django from loading any templates at all using it solely as a backend data layer that interacts with a database? We tried just deleting paths and/or template set ups in settings.py but it didn't help: STATIC_ROOT = os.path.join(BASE_DIR, 'ui/dist') STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', ) TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'APP_DIRS': True, 'DIRS': [ os.path.join(BASE_DIR, 'ui/dist'), os.path.join(BASE_DIR, '/data'), ], 'OPTIONS': { 'context_processors': [ 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] -
Filtering through relationship in views or template
I have one simple model called Product class Product(models.Model): title = models.CharField(max_length=150) def __str__(self): return self.title And one other model called ExternalProduct class ExternalProduct(models.Model): title = models.CharField(max_length=100) external_id = models.CharField(max_length=25) internal_product = models.ForeignKey( Product, on_delete=models.CASCADE, blank=True, related_name='external_products', ) price = models.IntegerField() brand = models.ForeignKey(Brand, on_delete=models.CASCADE, blank=True) image_url = models.CharField(max_length=255) product_url = models.CharField(max_length=255) store = models.CharField(max_length=50) active = models.BooleanField(default=True) class Meta: ordering = ['price'] def __str__(self): return self.title On the detailed view of the Product, I want to display the price of all ExternalProduct related to the Product. It works all fine with this view # products/views.py class ProductDetailView(DetailView): model = Product context_object_name = 'product' template_name = 'products/product_detail.html' and this template # product_detail.html {% extends '_base.html' %} {% block title %}{{ product.title }}{% endblock title %} {% block content %} <div class="book-detail"> <h2>{{ product.get_active_external_products }}</h2> </div> <div> <ul> {% for ep in product.external_products.all %} <li>{{ ep.price }}</li> {% endfor %} </ul> </div> {% endblock content %} The problem is that I just want to display the price of ExternalProduct which has active=True Been trying to solve it with a custom method in products views.py class ProductDetailView(DetailView): model = Product context_object_name = 'product' template_name = 'products/product_detail.html' def get_active_external_products(self): return self.external_products.objects.filter(active=True) And a … -
Creating a Popup Menu from a link using django, css and html
I want to know how to reference a particular section in a page in django. I know it's possible in html using a class or an id but I have tried it in django and I facing difficulties. I am creating popup menu when a linked is clicked. I have created it but how do you link it inside of the same page using Django. What I mean is how do Django does self referencing using links in a page not with models just like how html uses the class tag or the id value to link the section in the page. Thanks. https://enmascript.com/articles/2019/09/26/toggle-content-on-click-without-javascript[I want to do something like this in django still using the same html template and in the same page. ][1] -
Adding and rendering comments using django_comments
I recently started learning Python and Django and decided to make a blog as my first project, using Python 3.9.6 and Django 3.2.5. To include a comment section, I installed django_comments and followed the documentation. After migrating the new models, I tried adding a comment through the Django Admin site, but couldn't get it to render including {% render_comment_list for post %} in post_detail.html. In order to find where the issue lies, I tried adding the following django_comments template tags to see if it was a problem with render_comment_list or something else. {% get_comment_count for post as comment_count %} {{ comment_count }} It turned out the output was 0, so the reason no comments are displayed is that they are not being added. Here's the part I can't wrap my brains around: when adding a comment through the Django Admin site, choosing blog | entry as the content type and specifying the object_id, I don't get any errors, and supposedly the comment has been properly added. Also the "see in site" link for the comment takes me to the proper blog entry. Hopefully I explained myself well enough and some of you guys can spot what's probably an idiotic mistake. … -
How to delete child model data in case of on_delete=models.PROTECT?
Let assume i have two models Meeting and Call_Type and there is ForeignKey relation between them like bellow. class Meeting(SoftDeleteModel): name = models.call_type(CallType, on_delete=models.PROTECT, null=True) And:- class CallType(models.Model): type = models.CharField(max_length=256, null=False, blank=False, unique=True) Now i have deleted data from meeting table using Meeting.objects.all().delete() by mistake, and when trying delete CallType model data i get following error:- ProtectedError: ("Cannot delete some instances of model 'CallType' because they are referenced through protected foreign keys: 'Meeting.call_type'.", {<Meeting: Meeting object (1)>, <Meeting: Meeting object (2)>, <Meeting: Meeting object (3)>, <Meeting: Meeting object (4)>, <Meeting: Meeting object (5)>, <Meeting: Meeting object (6)>, <Meeting: Meeting object (7)>, <Meeting: Meeting object (8)>, <Meeting: Meeting object (9)>, <Meeting: Meeting object (10)>, <Meeting: Meeting object (11)>, <Meeting: Meeting object (12)>}) Is there is any way to delete CallType model data. Thanks in advance. Hope in here from you soon. -
send fabricjs drawing over WebSocket with django channels
I'm making a whiteboard and running it on localhost with different browser windows open. I can send shapes and textbox, but I can't figure out how to make a freedrawing appear in the canvas in the other windows. Code: HTML <button id="pencilBtn">Pencil Off</button> <canvas id="canvas"></canvas> JAVASCRIPT SENDER CODE: Click button to activate freedrawing: var pencilBtn = document.querySelector('#pencilBtn'); pencilBtn.addEventListener('click', pencilDrawing); function pencilDrawing(e){ if (e.target.textContent == 'Pencil Off'){ e.target.textContent = 'Pencil On'; canvas.freeDrawingBrush = new fabric.PencilBrush(canvas); canvas.set('isDrawingMode', true); canvas.freeDrawingBrush.width = 10; canvas.freeDrawingBrush.color = 'blue'; // Add some attributes to freeDrawingBrush canvas.freeDrawingBrush.brushtype = 'pencil'; canvas.freeDrawingBrush.user_id = user_id; canvas.freeDrawingBrush.toJSON = (function(toJSON){ return function(){ return fabric.util.object.extend(toJSON.call(this), { brushtype: this.brushtype, user_id: this.user_id }); }; })(canvas.freeDrawingBrush.toJSON); } else { e.target.textContent = 'Pencil Off'; canvas.set('isDrawingMode', false); } } MOUSE DOWN EVENT - (I know I'll need a mouse move and mouse up event, but I figured I'd start with just trying to send a drawing of a dot before anything else) canvas.on('mouse:down', (ev)=>{ if (canvas.isDrawingMode == true){ // Add another attribute to freeDrawingBrush canvas.freeDrawingBrush.obj_id = Math.random(); canvas.freeDrawingBrush.toJSON = (function(toJSON){ return function(){ return fabric.util.object.extend(toJSON.call(this), { obj_id: this.obj_id }); }; })(canvas.freeDrawingBrush.toJSON); // send freeDrawingBrush over socket whiteboardSocket.send(JSON.stringify({ 'canvas_object': { 'type': 'drawing_mouse_down', 'color': canvas.freeDrawingBrush.color, 'width': canvas.freeDrawingBrush.width, 'mouse_down_pointer': canvas.getPointer(ev), 'brushtype': canvas.freeDrawingBrush.brushtype, 'user_id': … -
Ajax funtion is through ann error Uncaught TypeError: $.ajax is not a function
I'm working on a Django project and I,m using Ajax to remove an item on a button click. I'm getting the error "Uncaught TypeError: $.ajax is not a function" every time when the button is clicked. I'm not an expert with javascript/Jquery. The way this ajax method is written has worked for me on other pages of the same product for a different function. But it is throwing error for this task Django Template <div class="menu-container"> <div class="container-heading"> <div class="row"> <span>Main Menu Section</span> </div> </div> <div class="box"> <div class="form-group"> <label for="{{ form.name.id_for_label }}"> Menu Name:<span style="color: red; font-weight: bold;">*</span> </label> <input type="text" name="menu_name" class="textinput form-control" pattern='[a-zA-Z\s]{1,250}' title="Alphabets and Spaces only" value="{{menu.name}}" required="true"> </div> {% for item in items %} <div class="row form-row"> <div id="item-{{forloop.counter}}-box" class="form-group col-md-10"> <label for="item-{{forloop.counter}}"> Item {{forloop.counter}}: </label> <input id="item-{{forloop.counter}}" type="text" name="{% if item.dishes %}{{item.slug}}{% elif item.drinks %}{{item.slug}}{% endif %}" class="textinput form-control" pattern='[a-zA-Z\s]{1,250}' title="Alphabets, Integers and Spaces only" value="{% if item.dishes %}{{item.dishes}}{% elif item.drinks %}{{item.drinks}}{% endif %}" required="true" disabled=""> </div> <div id="item-{{forloop.counter}}-box" class="form-group col-md-2"> <label for="remove-item" style="color: #fff"> . </label> <button class="menu_btn btn btn-danger delete-btn" type="button" id="remove-item-{{forloop.counter}}" onclick="removeItem({{forloop.counter}})">Remove</button> </div> </div> {% endfor %} </div> </div><div class="menu-container"> <div class="container-heading"> <div class="row"> <span>Main Menu Section</span> </div> </div> <div class="box"> … -
Filtering Posts greater than certain number of likes
I have a question about filtering Posts by Like count greater than a given number. What I want to achieve is on DJANGO SHELL when I type post.likes is greater than 10 I want to see all posts with more than 10 likes. How can I do that? Thanks models.py class Post(models.Model,HitCountMixin): likes = models.ManyToManyField(User, related_name="likes", blank=True) -
My view isn't rendering any result in the template - django
I'm working on a Django project and i'm quite the beginner so i'm really sorry if this is a basic question, my view isn't showing any result in the template, here's my view: def all_products(request): products = Product.objects.all() context = {'products': products} return render(request, 'users/home.html', context) this is the model: class Product(models.Model): title = models.CharField(max_length=255) id = models.AutoField(primary_key=True) price = models.FloatField(null=True) picture = models.ImageField(null=True) category =models.ForeignKey(Category,related_name='products',on_delete=models.SET_NULL,null=True) developer = models.ForeignKey(Developer, on_delete=models.SET_NULL, null=True) and finally this is the part of html needed: <div class="row justify-content-center" > {% for product in products %} <div class="col-auto mb-3"> <div class="card mx-0" style="width: 12rem; height:21rem; background-color: black;"> <a href="#"><img class="card-img-top img-fluid" style="width: 12rem; height:16rem;" src="{{ product.picture.url}}" alt="Card image cap"></a> <div class="card-block"> <a href="#"><h5 class="card-title mt-1 mb-0" style="color:white; font-size: 18px; font-family: 'Segoe UI';"><b>{{product.title}}</b></h5><a href="#"></a> <p class="card-text text-muted mb-1" style="color:white;">{{product.developer.title}}</p> <p class="item-price card-text text-muted"><strike >$25.00</strike> <b style="color:white;"> {{product.price}} </b></p> </div> </div> </div> <span></span> {% endfor %} </div> I also do have some product objects in my database, so where could the problem be? -
What is a robust network visualization tool that can be linked to Django web framework with a MySQL backend server?
I am trying to create a web-based protein-protein interaction network visualization graphic user interface. The web framework I am currently using is Django and my database is in MySQL. I would like the network visualization to be dynamic. That is to display the corresponding pathogen nodes based on what is selected in the drop-down list (i.e. "Select pathogen"). The drop-down list is populated by data in the MySQL database. What would be a recommended network visualization tool (preferably in Python) that can be linked to Django web framework with a MySQL backend server to display network graphs dynamically? I have previously used Networkx but I am not sure if it is able to link up with Django. -
Django Celery Periodic Task How to call Task method That is inside class
I want to send periodic mail to certain user After the user has been registered to certain platform I tried to send email using celery which works fine and Now I want django celery to send periodic mail as of now I have set the email time period to be 15 seconds. Further code is here celery.py app.conf.beat_schedule = { 'send_mail-every-day-at-4': { 'task': 'apps.users.usecases.BaseUserUseCase().email_send_task()', 'schedule': 15 } } I have my Class in this way ->apps.users.usecases.BaseUserUseCase.email_send_task here is my usecases to send email class BaseUserUseCase: def _send_email(self, user, request): self.user_instance = user self._request = request token = RefreshToken.for_user(user=self.user_instance).access_token # get current site current_site = get_current_site(self._request).domain # we are calling verify by email view here whose name path is activate-by-email relative_link = reverse('activate-by-email') # make whole url absolute_url = 'http://' + current_site + relative_link + "?token=" + str(token) # absolute_url = 'http://localhost:3000' + relative_link + "?token=" + str(token) self.context = { 'user': self.user_instance.fullname, 'token': absolute_url } self.receipent = self.user_instance.email @shared_task def email_send_task(self): print("done") return ConfirmationEmail(context=self.context).send(to=[self.receipent]) How do I call this email_send_task method am I doing right any help regarding this It is not working.