Hi,
I’m stuck with the error ‘Method Not Allowed (POST)’ while using the contact form for my site. As I’m newbie to django I can’t figure out what’s wrong with my code, so please help me with this one :)
Here is my code:
views.py :
def contact(request) :
form_class = ContactForm
if request.method == 'POST':
form = form_class(request.POST)
if form.is_valid():
first_name = request.POST.get('first_name', '')
last_name = request.POST.get('last_name', '')
company_name = request.POST.get('company_name', '')
contact_email = request.POST.get('email', '')
phone = request.POST.get('phone', '')
form_content = request.POST.get('content', '')
template = get_template('contact_template.txt')
context = {
'first_name': first_name,
'last_name': last_name,
'company_name': company_name,
'contact_email': contact_email,
'phone': phone,
'form_content': form_content,
}
content = template.render(context)
email = EmailMessage(
"New contact form submission",
content,
"Your website" +'',
['[email protected]'],
headers = {'Reply-To': contact_email }
)
email.send()
return redirect('contact')
return render(request, 'index.html', {'form': form_class})
I’m using this contact form for single page site.