提问人:THOMAS MASSALEY 提问时间:8/22/2023 更新时间:8/22/2023 访问量:20
Django 联系表单 POST。 不允许 405 方法
Django Contact Form POST. 405 Method Not Allowed
问:
我希望这篇文章能找到你。 我的 django 项目(代码)遇到了问题,我需要您的帮助。
当我填写表单并单击提交按钮时,我希望被定向到成功页面,但我的终端中不断收到“不允许的方法 (POST):/success/”和“此页面不起作用如果问题仍然存在,请与网站所有者联系。HTTP 错误 405“显示在我的屏幕(浏览器)上。
谢谢。
这是我的联系表格 HTML 代码:
<form class="p-6 flex flex-col justify-center bg-gray_like rounded-lg"
method="POST" action="{% url 'base:success' %}"> {% csrf_token %}
<div class="flex flex-col">
<label for="name" class="hidden">Full Name</label>
<input type="text" name="name" id="name" placeholder="Full Name"
class="w-100 mt-2 py-3 px-3 rounded-lg bg-white border border-blue text-black font-md focus:border-blue focus:outline-none"></div>
<div class="flex flex-col mt-2">
<label for="email" class="hidden">Email</label>
<input type="email" name="email" id="email" placeholder="Email" class="w-100 mt-2 py-3 px-3 rounded-lg bg-white 0 border border-blue text-black font-md focus:border-blue focus:outline-none"></div>
<div class="flex flex-col mt-2">
<label for="subject" class="hidden">Subject</label>
<input type="text" name="subject" id="subject" placeholder="Subject"
class="w-100 mt-2 py-3 px-3 rounded-lg bg-white border border-blue text-black font-md focus:border-blue focus:outline-none"></div>
<div class="flex flex-col mt-2">
<label for="message" class="hidden">Message</label>
<textarea type="text" name="message" id="message" placeholder="Message"
class="w-100 mt-2 py-3 px-3 rounded-lg bg-white border border-blue text-black font-md focus:border-blue focus:outline-none"></textarea></div>
<button type="submit" class="md:w-35 bg-blue hover:bg-blue-dark text-white font-bold py-3 px-10 rounded-lg mt-3 hover:bg-indigo-500 transition ease-in-out duration-300">Send Message</button>
</form>
这是我 veiw.py
#Contact Form view
class ContactView(FormView):
def post(self, request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid(): #Form validation
#extract data from the form
name = form.cleaned_data['name']
email = form.cleaned_data['email']
subject = form.cleaned_data['subject']
message = form.cleaned_data['message']
# send email to recipient
send_mail(
'CONTACT FORM SUBMITTED',
f'Name: {name}\nEmail: {email}\nSubject: {subject}\nMessage: {message}',
'[email protected]',
['[email protected]','[email protected]'],
fail_silently= False)
return render(request,'/success.html')
else:
form = ContactForm()
return render(request,'contact.html/',{'form':form})
这是我的基本应用程序 url 代码:
app_name = 'base'
urlpatterns = [
path('', views.HomePageView.as_view(), name='home'),
path('services/', views.ServicesPageView.as_view(), name='services'),
path('about_us/', views.About_UsPageView.as_view(), name='about_us'),
path('price/', views.PricePageView.as_view(), name='price'),
path('portfolio/', views.PortfolioPageView.as_view(), name='portfolio'),
path("<int:pk>/", views.ProjectDetailView.as_view(), name='project_detail'),
path('contact', views.ContactView.as_view(), name='contact'),
path('success/', views.SuccessPageView.as_view(), name='success'),
]
终端中的错误消息:
“不允许的方法 (POST):/success/ 不允许的方法:/success/ [22/8月/2023 05:59:19]“POST /success/ HTTP/1.1” 405 0”
答: 暂无答案
评论