我在我的django应用程序中有表单,即ajax中的send_email。但是当我在我的托管上部署它时,它对提交没有反应......我甚至不明白我如何调试它。 我已经删除了函数send_mail,只是尝试进行重定向,甚至只是提交HttpResponse,但是当点击提交时,它确实有效,并且没有向我的控制台显示任何错误..
这是代码:
forms.py
from django import forms
class ContactForm(forms.Form):
user_name = forms.CharField(label='name', max_length=128, required=True)
email = forms.EmailField(label='Email', max_length=128, required=True)
subject = forms.CharField(label='subject', max_length=128, required=True)
message = forms.CharField(label='message', widget=forms.Textarea, required=True)
views.py
from django.shortcuts import render, HttpResponse, redirect
from .forms import ContactForm
def contacts(request):
form = ContactForm(request.POST or None)
if form.is_valid():
user_name = request.POST.get('user_name', '')
email = request.POST.get('email', '')
subject = request.POST.get('subject', '')
message = request.POST.get('message', '')
return HttpResponse('Success!')
ctx = {
'form': form,
}
return render(request, 'contacts.html', ctx)
contacts.html
<form method="post" id="contact-form">
{% csrf_token %}
{% bootstrap_form form %}
<div class="form-group">
<input type="submit" class="btn button">
</div>
</form>
抱歉英文不好。