Hi,
I am trying to send a file as an attachment in an email. It works
fine when I attachment file is hardcoded. But when I try to use
FileInput widget, I just get the filename in request.FILES dictionary.
Is it possible to get full path of the file? Am I using wrong widget
for this purpose? Can anyone please help me, thanks
---Form ----
class EmailForm(forms.Form):
subject = forms.CharField(max_length=100)
attachment = forms.CharField(widget = forms.FileInput)
email = forms.EmailField()
message = forms.CharField()
---Views-----
def send_email(request):
if request.method != 'POST':
form = EmailForm()
return render_to_response('admin/Email.html', {'email_form':
form})
form = EmailForm(request.POST, request.FILES)
if form.is_valid():
subject = form.cleaned_data['subject']
message = form.cleaned_data['message']
email = form.cleaned_data['email']
attachment = request.FILES['attachment']
try:
mail = EmailMessage(subject, message,
settings.EMAIL_HOST_USER,
[email])
mail.attach_file(attachment)
mail.send()
return render_to_response('admin/Email.html',
{'message': 'Sent
email']})
except:
return render_to_response('admin/Error.html',
{'message': 'Error'})
return render_to_response('admin/Email.html', {'message': 'Unable to
send email. Please try again later'})
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---