0π
β
After two days, I finally got the solution. The error was in the urls.py file. (So next time I will include urls.py as well) Thanks for helping guys!
I was using a TemplateView:
url(r'^$', TemplateView.as_view(template_name='contact/contact-form.html'), name="contact-form"),
Instead of adding the view I created so that it would be possible to show and process the form.
url(r'^$', 'contact.views.contact', name="contact"),
π€manosim
1π
Its not good practice to use template_name inside url.
try with this :
url(r'^/contact$','appname.views.contact',name='contact')
π€hizbul25
- [Answer]-How to arrange fields of a form rendered by ModelForm?
- [Answer]-Django Static Javascript Asset with JQuery Functions
- [Answer]-How can I check that two records contain the same information in 3 specific fields?
0π
This should work..
from django.core.context_processors import csrf
def contact(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
name = form.cleaned_data['name']
email = form.cleaned_data['email']
message = form.cleaned_data['message']
recipients = ['myemail@outlook.com']
send_mail(name, email, message, recipients)
return HttpResponseRedirect(reverse('contact-thanks'))
else:
form = ContactForm()
args = {'form' : form}
args.update(csrf(request))
return render(request, 'contact/contact-form.html', args)
π€Anish Shah
- [Answer]-Use named URLs in @login_required decorator
- [Answer]-Gunicorn is unable to find my wsgi file, not able to load python?
Source:stackexchange.com