Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Passnig paramters via URL to template not working (404)
I have a link in a table which works with the following url path: f"""<a href="/link/{record.id}"><button class="btn">link</button></a>""" path(r'link/<int:pk>/', views.AssocView.as_view(), name="link") which works fine in combination. As soon as I want to pass another integer to the view, I get a 404: f"""<a href="/link/{record.id}/??test_id=12345/"><button class="btn">link</button></a>""" path(r"link/<int:pk>/(?P<test_id>[0-9]+)/(?P<test_2_id>[0-9]+)/", views.AssocView.as_view(), name="link"), AssocView: class AssocView(TemplateView): model = Product template_name = "app/product_all.html" def get_success_url(self): return redirect("product-all") def get_context_data(self, **kwargs): context = super(AssociateView, self).get_context_data(**kwargs) context["table"] = Product.objects.all() return context As soon as I add URL parameters like test_id I get a 404 - what am I missing here? Could it be because something is interfering? Middleware with response = self.get_response(request) or so? Error: Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8001/link/35/?test_id=12345&test_2_id=221 -
Adding products and services to the cart from different apps
Hi Everyone, I am new to python and django and creating a fitness website. I have three apps, one is for the products, one for exercise plans and one for nutrition plans. I am able to add the products in the shopping cart. But wonder how can i do this for the exercise plan app and nutrition plan app. Can any one please suggest a simple way out please. -
Read Data from a PDF image python django
I have a PDF and its like images in pdf . and I want to read text from it . I tried to use PyPDF4 but it works only if pdf is in text form . in 2nd step I searched futher and found pytesseract . But Not found any link to convert PDF image to text. Any help would be highly appreciated. Thanks -
form.cleaned_data.get is not producing any data from my form when posted
form.cleaned_data.get is not getting the data I need from a dropdown from a database. I have a database table that filters by an 'area' selection then uses Ajax to load in the 'machine' list that corresponds to that 'area'. I then select the 'machine' I want from that loaded dropdown and submit. This goes to a new page based off of that selection. The problem I'm running into is in 'def post' machine_id = form.cleaned_data.get('machine') returns None so there is no information for the next loaded page. I have tested it with form.cleaned_data.get('area') and that returns the area selected from the dropdown. All values on the database are filled out. Thank you! Views.py: class MachineSelectView(TemplateView): template_name = 'machines/machine_select.html' def get(self, request): form = MachineSelectForm() args = {'form':form} return render(request, self.template_name, args) def load_machines(request): area_id = request.GET.get('area') MACHINE_CHOICES_UNSORTED = list(Tasks.objects.values_list('machine', flat=True).filter(area=area_id).exclude(machine__isnull=True)) MACHINE_CHOICES = list(dict.fromkeys(MACHINE_CHOICES_UNSORTED)) machine = MACHINE_CHOICES return render(request, 'machines/machine_dropdown_list_options.html', {'machines': machine}) def post(self, request): form = MachineSelectForm(request.POST) form.is_valid() machine_id = form.cleaned_data.get('machine') return redirect('/machines/%s/'%(machine_id)) Forms.py (These are text imputs that I've changed to dropdowns so the table can also be written to.) class MachineSelectForm(forms.ModelForm): area = forms.ChoiceField(choices=AREA_CHOICES) machine = forms.ChoiceField() class Meta: model = Tasks fields =( 'area', 'machine', ) def … -
How to display form validation error on HTML template in Django
How should I display the error messages on the HTML template, for Example I write a condition in the forms.py that if username already exist in the database, it should display the message on the HTML page, How should I do this? Following is my code: View.py from django.shortcuts import render,redirect from django.views.generic import View,TemplateView from .forms import Registration_Form from .models import User_Registration from django.contrib import messages # Create your views here. class MainPageView(TemplateView): template_name='main.html' class LoginView(TemplateView): template_name='login.html' def RegistrationView(request): form=Registration_Form() if request.method=='POST': form=Registration_Form(request.POST) if form.is_valid(): user_name=form.cleaned_data['username'] print(User_Registration.objects.filter(username=user_name)) form.save() return redirect('login_view') else: # messages.error(request,"Form is Invalid!") return redirect('registration_view') else: return render(request,'registration.html',{'form':form}) # template_name='registration.html' forms.py from django import forms from .models import User_Registration class Registration_Form(forms.ModelForm): class Meta: model=User_Registration fields=('company_name','username','password','email') widgets={ 'company_name':forms.TextInput(attrs={'class':'form-control input-sm'}), 'username':forms.TextInput(attrs={'class':'form-control'}), 'password':forms.PasswordInput(attrs={'class':'form-control'}), 'email':forms.EmailInput(attrs={'class':'form-control'}), } def clean(self): user_name=self.cleaned_data['username'] if User_Registration.objects.filter(username=user_name).exists(): raise forms.ValidationError("Username Already Exist") -
Why The Image Is Not Being Rendered In Html Template Even Being Added To Static Files - Django?
I have tried using the image address in the normal HTML file, and it works great, but as I try to render the image with an HTML template with Django all it shows is just an image placeholder. And When I Inspect The Image Element It Has The Correct Src Attribute But Still It Doesn't Load. Here Is The Peace Of HTML <h1>{{article.title}}</h1> <div class="box"> <img src= "{{article.article_thumbnail_image_url}}" alt="Failed To Load Thumbnail Image"> </div> -
UnicodeDecodeError: skipped file doc1_UTF-16BE.html in
in the same error I had Ubuntu v20x Python 3.8.4 Django 3.0.2 / venv I wanted to internationalize my site but when calling django-admin makemessages --all I was getting this error. UnicodeDecodeError: skipped file doc1_UTF-16BE.html in ./venv/lib/python3.8/site-packages/weasyprint/tests/resources (reason: 'utf-8' codec can't decode byte 0xdc in position 339: invalid continuation byte) processing locale ru processing locale en Solutions. i changed encoding on the file doc1_UTF-16BE.htmlto doc1_UTF-8.html and coding to utf-8 please tell me, did I do the right thing? -
Issue with using query in Django
So what I'm trying to get is the following. User can choose 3 categories as seen in the code. Inside those categories they can add any number of plants. In my view: collection I want the user to see the following: COLLECTION Category_selected_by_user plant_1 plant_2 .... Category_selected_by_user2 What I get right now is: COLLECTION Category_selected_by_user Category_selected_by_user2 Category_selected_by_user3 so basically this is the code in models.py: class Plant_name(models.Model): """This class contains the plant name that is housed within a certain category""" """Links the plant to one of the chosen categories""" category = models.ForeignKey(Plant_category, on_delete=models.CASCADE, related_name='plant_names') # Placeholder for connection with a plant database API plant = models.CharField(max_length=50) """Return the plant input from the user""" def __str__(self): return self.plant this is the code in views.py: def collection(request): """The page that opens the collection of plants""" plant_categories = Plant_category.objects.all().order_by('category') context = { 'plant_categories': plant_categories, } return render(request, 'plntz_main/collection.html', context) And this is the code in collection.html: <ul> {% for category in plant_categories %} <h3>{{ category }}</h3> {% for name in plant_categories.plant_names.all %} <li>{{ name.plant }}</li> {% endfor %} {% empty %} <li>No category has been added yet.</li> {% endfor %} There must be something wrong with the data pulled for the plants inside … -
Error When Importing requirements.txt to project on Ubuntu Server(Digital Ocean)
I am currently trying to import my requirements.txt from my local django project to my django project on the my Ubuntu Server in digital ocean. Each time I run my pip command to install the packages in "requirements.txt" I get the below error. Command I am currently running: pip install -r requirements.txt ERROR: Could not find a version that satisfies the requirement asgiref==3.2.10 (from -r requirements.txt (line 1)) (from versions: 0.8, 0.9, 0.9.1, 0.10.0, 0.11.0, 0.11.1, 0.11.2, 0.12.0, 0.12.1, 0.13.0, 0.13.2, 0.13.3, 0.14.0, 1.0.0, 1.0.1, 1.1.0, 1.1.1, 1.1.2, 2.0.0, 2.0.1, 2.1.0, 2.1.1, 2.1.2, 2.1.3, 2.1.4, 2.1.5, 2.1.6, 2.2.0, 2.3.0, 2.3.1, 2.3.2, 3.0.0, 3.1.0, 3.1.1, 3.1.2, 3.1.3, 3.1.4, 3.2.0, 3.2.1, 3.2.2, 3.2.3) ERROR: No matching distribution found for asgiref==3.2.10 (from -r requirements.txt (line 1)) -
Handling fetch api in javascript
I am working on a twitter like web page. In one single page I have a form to write a tweet and enough space down there to show the tweets. To asynchronously show them, I`m using fetch api to intercept the form and do this dynamically: document.querySelector('form').onsubmit = (event) => { event.preventDefault(); fetch("", { method: 'POST', body: JSON.stringify({ body: document.querySelector('#new_message').value }), headers: { "Content-type": "application/json; charset=UTF-8", "X-CSRFToken": getCookie('csrftoken') } }) .then(response => response.json()) .then(result => { document.querySelector('#new_message').value = "" let div = document.createElement('div') div.innerHTML = ("<p>" + result.creation_date + "</p>" + "<a href='#'>" + result.username + "</a>" + ' said:' + '<br><br>' +"<div class='container'>" + "<p>" + result.body + "</p>" + "</div>"); div.style.cssText = "box-shadow: 0px 0px 2px; ; background-color:#F5F5F5; border-radius:10px; padding: 10px; margin: 5px;"; document.querySelector('#posts').append(div); }); } This dinamically shows the tweet when it`s posted without reloading the html. But the problem comes when I want to show the tweets them when a user actually reloads the page, I mean, via a get method: if request.method == "GET": if request.user.is_authenticated: posts = Posts.objects.all().order_by('-creation_date') return render(request, "network/index.html", { "posts":posts }) else: return render(request, "network/login.html") This makes me handle the tweet html from the javascript code and also with django templating … -
Can't reach Django server
I have begun working on a Django project and am testing whether Django is working. I have just started a project with django-admin startproject testing I haven't done anything to the project and have simply tried to run python manage.py runserver to make sure Django is working. Unfortunately when I try to access the server I simply get this: This site can’t be reached 127.0.0.1 refused to connect. Try: Checking the connection Checking the proxy and the firewall ERR_CONNECTION_REFUSED Could somebody tell me how I can actually access my Django project? I am using CS50 IDE on Google Chrome. -
creating a folder automatically for each user Django
So I am trying to create a folder automatically for each user in Django when they first sign up, where all their stuff gets saved in that folder. What I tried: #Creating a folder automatically for each user def folder_path(instance, filename): return "user_{0}/MyFolder/{1}".format(instance.user.id, filename) # Create your models here. class MyModel(models.Model): user = models.ForeignKey(User, on_delete= models.CASCADE, default= None) user_folder = models.FileField(upload_to= folder_path, default= None) views.py myfolder = MyModel(user_folder= '/path/to/folder/') I also tried: #Creating a folder automatically for each user def folder_path(instance, filename): user = instance.user.username basename, file_extension = filename.split(".") new_filename = "%s-%s.%s" %(user, instance.id, file_extension) return "MyFolder/%s/%s" %(user, new_filename) # Create your models here. class MyModel(models.Model): user = models.ForeignKey(User, on_delete= models.CASCADE, default= None) user_folder = models.FileField(upload_to= folder_path, default= None) views.py myfolder = MyModel(user_folder= '/path/to/folder/') I want to know why its not working, it does not give an error, but does not create a folder automatically. Thanks. -
How to expose Django Rest APIView fields to swagger?
I have something like this: class MyCustomView(APIView): serializer_class = serializers.MyCustomSerializer def post(self, request): #my custom logic here, working on multiple tables, etc But the serialization fields do not show up in swagger or default Django rest HTML view. How can I make it so it does? -
Getting this error after running 'manage startapp user'
Hey I have been working with django these days and it worked for me fine until now it is just giving me this error after running the command manage startapp user in my environment. It actually does create the app but also responded with this error. Traceback (most recent call last): File "E:\django\Amron\MyCafe\manage.py", line 22, in <module> main() File "E:\django\Amron\MyCafe\manage.py", line 18, in main execute_from_command_line(sys.argv) File "E:\django\Amron\env\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line utility.execute() File "E:\django\Amron\env\lib\site-packages\django\core\management\__init__.py", line 395, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "E:\django\Amron\env\lib\site-packages\django\core\management\base.py", line 341, in run_from_argv connections.close_all() File "E:\django\Amron\env\lib\site-packages\django\db\utils.py", line 230, in close_all connection.close() File "E:\django\Amron\env\lib\site-packages\django\utils\asyncio.py", line 24, in inner return func(*args, **kwargs) File "E:\django\Amron\env\lib\site-packages\django\db\backends\sqlite3\base.py", line 261, in close if not self.is_in_memory_db(): File "E:\django\Amron\env\lib\site-packages\django\db\backends\sqlite3\base.py", line 380, in is_in_memory_db return self.creation.is_in_memory_db(self.settings_dict['NAME']) File "E:\django\Amron\env\lib\site-packages\django\db\backends\sqlite3\creation.py", line 12, in is_in_memory_db return database_name == ':memory:' or 'mode=memory' in database_name TypeError: argument of type 'WindowsPath' is not iterable Also the server stops reloading after I save to any of the project files. Really need your help. Thanks!! -
django redirect user to the post after creating it
i want to redirect the user to the post after creating in with django forms in models.py class Text(models.Model): title = models.CharField(max_length=200, null=True) document = models.TextField(max_length=None, null=True) requirements = models.TextField(max_length=200, null=True) date_created = models.DateField(auto_now_add=True, null=True) deadline = models.DateField(null=True) author = models.ForeignKey(User, on_delete=models.CASCADE, null=True) def __str__(self): return self.title in my view.py def text(request, pk): form = TextForm() if request.method == "POST": form = TextForm(request.POST) if form.is_valid(): text = form.save() text = Text.objects.get(id=pk) return redirect('text') text = Text.objects.get(id=pk) context = {'form': form, 'text': text} return render(request, 'main/text.html', context) in my forms.py class TextForm(ModelForm): class Meta: model = Text fields = ['title','document','requirements','deadline'] widgets = { 'title' : forms.TextInput(attrs={'placeholder':'Title','class':'form-control m-2 mb-4 pb-2'}), 'deadline' : forms.DateInput(attrs={'placeholder':'Deadline','type':'date','class':'form-control m-2 pt-2', 'id':'opendate'}), 'requirements' : forms.Textarea(attrs={'placeholder':ps_note,'class':'form-control col m-2','rows':'3'}), 'document' : forms.Textarea(attrs={'placeholder':ps_text,'class':'form-control'}), } i had to add this to be able to the question gets accepted -
attribute error: 'int' object has no attribute 'get'
i am trying to make this request for a checkout id in a payment process and this is my code so far. the code below works fine and i get a response from it, but as soon as I add some of the commented parts to the data dictionary it gives me an attribute error saying that int has no object get. basically, i seem to only be able to add keys and string or number values to my data dict, but whenever i add a dict as a value it starts giving me the error. i have no idea why this is happening, can anyone help? thanks in advance! def request_checkout_id(request): user = request.user url = "https://xxxxxx" entity_id = 'xxxxx' auth_header = 'xxxxx' currency = 'USD' try: ref_code = request.session['ref_code'] order = Order.objects.get(ref_code=ref_code) except: ref_code = None return redirect(reverse('shop:cart')) amount = float(order.final_total) base_con_tarifa = order.cart.total valor_iva = order.cart.tax_total #total_con_iva = order.sub_total base_sin_tarifa = order.shipping_price custom_param = '0081004012'+ str(valor_iva).replace(".", "").zfill(12) + '052012' + str(base_sin_tarifa).replace(".", "").zfill(12) + '003007010391005100817913101053012' + str(base_con_tarifa).replace(".", "").zfill(12) print(custom_param) data = {} # cart = {} # items = [] # i = 0 # for item in order.cart.cartitem_set.all(): # items.append({}) # items[i]['name'] = item.product.name # items[i]['description'] = … -
Django Crispy Forms: Set rows for Text Area
When creating a Form with FormHelper(), the text areas of my form (for TextFields) are too big: They are set to 10 rows. I'd like to set the number of rows. How can I do that? My code: models.py: from django.db import models class Spam(models.Model). ham = models.CharField(max_length=10, blank=True, null=False, default='Some ham') eggs = models.TextField(blank=True, null=False, default='', verbose_name="Lots of eggs") forms.py: from django import forms from crispy_forms.helper import FormHelper from crispyy_forms.layout import (Layout, Row, Column) from .models import Spam class SpamForm(forms.ModelForm): class Meta(): model = Spam fields = ('ham', 'eggs') def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_method = 'POST' self.helper.layout = Layout( Row(Column('ham', css_class='form-group col-12')), Row(Column('eggs', css_class='form-group col-12')), # HERE: How can I set the rows for the text area widget? ) Resulting HTML: <!-- (ommited for brevity) --> <div class="form-row " > <div class="form_group col-12" rows="2"> <div id="div_id_eggs" class="form-group"> <label for="eggs" class="">Lots of eggs</label> <div class=""> <textarea name="eggs" cols="40" rows="10" class="textarea form-control" id="eggs"></textarea> <!-- ^^^^^^^^ <!-- THIS is what I'd like to change to "2" --> </div> </div> </div> </div> <!-- (ommited for brevity) --> -
Django template does not exist include or extends tags
I am creating a Django project. My question is simple I believe but I am having a tough time trying to figure it out. I have an index.html in which I want to render certain things. I decided that I don't want to have a html header for every one of my html pages which to me is insane. I created a base.html file to contain a html header and I want to reuse this for my other html files but how do I do this exactly, that is if it's possible. So what I am mostly not sure about is which tag to use {% include "base.html" %} or {% extends "base.html"%}. Intuition is telling me I should use {% include "base.html" %} because I don't believe I should be inheriting. And then my second question which relates close to this is how do I even include or extends. I just created a base.html file and an index.html file and have a index view in my views file which renders the index.html with context. Everything works fine if I were to just use the index.html file but when I do {% include "base.html" %} in my index.html file it … -
Cannot set django user password
email or username is captured and stored in userinput userinput = request.POST['usrmail'] if(re.search(regex,userinput)): # username = userinput.split("@")[0] try: userdelta = get_object_or_404(MyUser, email=userinput) except MyUser.DoesNotExist: pass else: try: userdelta = get_object_or_404(MyUser, username=userinput) except MyUser.DoesNotExist: context = {'error': 'Kindly get registered'} return render(request, 'am/forgotpassword.html', context) userpassword = MyUser.objects.make_random_password(length=8) <This line doesn't works> userdelta.set_password(userpassword) -
Deleted a folder, get ModuleNotFoundError: No module named "api"
I am using Django and trying to use Django Rest Framework as well. Since I had never used Django Rest Framework, I did a kind of tutorial by following an article. To do this, I created a new app by entering python manage.py startapp app. After I finished the tutorial, I deleted this app in order to work on my project. However, when I try to make the server run I got this error. (venv) (base) MacBook-Air-4:extra_exchange user$ python manage.py makemigrations Traceback (most recent call last): File "manage.py", line 22, in <module> main() File "manage.py", line 18, in main execute_from_command_line(sys.argv) File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line utility.execute() File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/core/management/base.py", line 330, in run_from_argv self.execute(*args, **cmd_options) File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/core/management/base.py", line 368, in execute self.check() File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/core/management/base.py", line 396, in check databases=databases, File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/core/checks/registry.py", line 70, in run_checks new_errors = check(app_configs=app_configs, databases=databases) File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/core/checks/urls.py", line 13, in check_url_config return check_resolver(resolver) File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/core/checks/urls.py", line 23, in check_resolver return check_method() File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/urls/resolvers.py", line 408, in check for pattern in self.url_patterns: File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/utils/functional.py", line 48, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/urls/resolvers.py", line 589, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "/Users/user/Desktop/my_project/extra_exchange/venv/lib/python3.7/site-packages/django/utils/functional.py", line 48, in __get__ … -
how to make print first page have a diffrent margin, django
how can i make the first print page have a different margin? i use xhtml2pdf to convert html to pdf i already try to use @page { size: A4; margin-top: 2.54cm; margin-bottom:2.54cm ; } @page :first{ margin-top: 10cm; } but i getting error page = page + '_' + pseudopage TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' so how i can make a different margin in first print page? -
Django - how to delete a user/profile with a delete button
Hey I have a delete button on my profile page views.py def list_all(request): context = { 'users': User.objects.all } return render(request, 'users/list_all.html', context) signals.py @receiver(post_save, sender=User) def delete_profile(sender, instance, created, **kwargs): if created: Profile.objects.delete(user=instance) models.py def __delete__(self, instance): super().delete() forms.py class ProfileDeleteForm(forms.ModelForm): class Meta: list_all.html {% extends "myfarm/base.html" %} {% load static %} {% block content %} {% for user in user %} <p>Username: {{ user.username }}</p> {% endfor %} {% endblock content %} Right now I only get a message that I usually get for when I press the "update" button. What do I need to add in order to delete the user from the data base ? -
Django check Windows ID in user_passes_test
I am trying to check to see if a user is in a particular user group in my Django application. Here is my current code that works perfectly fine: def user_check_group(user): return user.groups.filter(name='group').exists() @user_passes_test(user_check_group) def myview(request): # renders my view However, this requires users to be logged into the application, which I really don't want them to have to do. I want to be able to verify by the Windows username rather than the user logged into the Django application. I understand there are security concerns doing this method, but lets put those aside for now. What I tried to do: def user_check_group(user): username = os.environ.get('USERNAME') return username.groups.filter(name='group').exists() This properly fetches the Windows username, but I get an error 'str' object has no attribute 'groups'. I know why this is happening, but don't know how to access the groups to check for a windows username instead of the Django username. Any ideas? -
I added a 'name' field to my django custom user, It is requested on creation but gets saved as a default 'objects' for all created users
I added a field 'name' to my custom Django user model, it is requested when I run createsuperuser and even when I create a normal user from the shell with create_user(), but when I query all my User objects, they all have a default value of 'objects' stored in user.name and that is what is displayed on the admin site too. I have tried to modify the manager by adding user.name = name before the save() method but I still get the same result. my models.py: from django.contrib.auth.models import AbstractUser from django.db import models from django.utils.translation import gettext_lazy as _ from .managers import CustomUserManager class User(AbstractUser): email = models.EmailField(_('email address'), unique=True, blank=False) name = models.CharField( _('full name'), max_length=100, blank=False, null=False) username = None USERNAME_FIELD = 'email' NAME_FIELD = 'name' def get_full_name(self): return self.name.strip().title() def get_short_name(self): return self.name.title().split()[0] def __str__(self): return self.get_full_name() REQUIRED_FIELDS = ['name', ] objects = CustomUserManager() my managers.py: from django.contrib.auth.base_user import BaseUserManager from django.utils.translation import ugettext_lazy as _ class CustomUserManager(BaseUserManager): """ Custom user model manager where email is the unique identifiers for authentication instead of usernames. """ def create_user(self, email, name, password, **extra_fields): """ Create and save a User with the given email, name and password. """ if … -
How to send images in email through django
This is in my views.py : subject='Thank you for your order from cottgin.in' message=f'Your order id is {a}' from_email=settings.EMAIL_HOST_USER to_list=[order.customer.user.email] send_mail(subject,message,from_email,to_list,fail_silently=True) I am sending the order info to the user after he places the order but I also want to send some images like the item images as well as the logo . how do i do that.Can I send a html template in mail? I havent found any proper solution to this on internet so any help would be appreciated.