0% found this document useful (0 votes)
10 views1 page

If Request - Method 'POST' and Req

The document outlines a process for handling a POST request that includes file uploads, where user contact information is collected and saved to a database. An email confirmation is sent to the user acknowledging receipt of their message, and a success message is displayed. Finally, the user is redirected to a specified page after submission.

Uploaded by

anjalumeche
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

If Request - Method 'POST' and Req

The document outlines a process for handling a POST request that includes file uploads, where user contact information is collected and saved to a database. An email confirmation is sent to the user acknowledging receipt of their message, and a success message is displayed. Finally, the user is redirected to a specified page after submission.

Uploaded by

anjalumeche
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

if request.method == 'POST' and request.

FILES:
name = request.POST.get('name')
email = request.POST.get('email')
phone = request.POST.get('phone')
message = request.POST.get('message')

# Save to database
Contact.objects.create(
name=name,
email=email,
phone=phone,
message=message
)

# Send email to the user


subject = 'Thank you for contacting us!'
email_message = f"""
Hello {name},

Thank you for reaching out to us. We have received your message and will
get back to you shortly.

Your Message:
{message}

Best regards,
The Momo Restaurant Team
"""
send_mail(
subject,
email_message,
'[email protected]', # Sender's email
[email], # Recipient's email
fail_silently=False,
)

# Display a success message


messages.success(request,f'Hi {name},Your message has been sent
successfully! Please check your mail')

# Redirect to the same page or a thank-you page


return redirect('home') # Replace 'home' with your desired URL name

return render(request,'momo/index.html')

You might also like