1👍
just remove the .url
from book_object
and send the book_object.read()
def send_book(request):
subject= 'the subject of this email'
message = 'body of this email'
recipient_email = 'customer@example.com'
from_email = 'platformemail@example.com'
email=EmailMessage(subject,message,from_email,[recipient_email])
email.content_subtype='html'
# the_domain = request.build_absolute_uri('/')[:-1]
book_object = Book.objects.get(title='Selfish Gene').bookfiles_set.all().first().file
# the_file=open(f'{the_domain}{book_object}',"r")
email.attach("file_name.pdf", book_object.read(),'application/pdf')
email.send()
0👍
Have you set the MEDIA_ROOT in your settings.py to the absolute path to where the files resides on the disk? And , if so, what is it set to?
As a reference to media settings in Django, have a look at this article:
https://testdriven.io/blog/django-static-files/#media-files
- [Answered ]-Django : render a view in other views
- [Answered ]-Django forms: not adding attributes
- [Answered ]-Can't sync south in db
- [Answered ]-Django 404 page not showing up
Source:stackexchange.com