在表单提交中使用post方法时出现运行时错误

问题描述 投票:0回答:1

标题:单击提交按钮时出现运行时错误(附加斜杠)

说明: 当我单击表单上的提交按钮时,遇到运行时错误。该错误提到了有关附加斜杠的内容。我试图理解它,但我被困住了。有人可以帮我找出导致此错误的原因以及如何解决它吗?我在我的项目中使用 python 和 django。

附加信息:

  • [如果可能请提供相关代码片段]
  • [收到的任何错误消息]

  <form  action="register" method="POST" onsubmit="register">
               {% csrf_token %}
               <h3>my information</h3>
               <h4>Contact us today, and get reply with in 24 hours!</h4>
               <style>
                 fieldset {
                   border: medium none !important;
                   text-emphasis-color:black;
                   margin: 0 0 10px;
                   min-width: 100%;
                   padding: 0;
                   width: 100%;
                   }
               </style>
               <fieldset>
                 <input placeholder="Your name" type="text" tabindex="1" style="background-color:black;"  required autofocus>
               </fieldset><br>
               <fieldset>
                 <input placeholder="Your Email Address" type="email" tabindex="2" style="background-color:black;" required>
               </fieldset><br>
               <fieldset>
                 <input placeholder="Your Phone Number" type="tel" tabindex="3" style="background-color:black;" required>
               </fieldset><br>
               <fieldset>
                 <label for="account">Choose a account:</label>
                   <select name="account" id="name">
                   <option value="netflix">netflix</option>
                   <option value="amazone prime">amazone</option>
                   <option value="disney plus hotstar">hotstar</option>
                   </select>
                   <style>
                   #nname {
                     padding: 5px;
                     color: #f7f7f8;
                     font-size: 12px;
                     background: black;
                     appearance: none;
                 
                 }
               </style>
               </fieldset><br>
               <fieldset>
                 <textarea placeholder="Type your Message Here...." tabindex="5" style="background-color:black;" required></textarea>
               </fieldset><br>
               <fieldset>
                 <button name="submit" type="submit" id="contact-submit" style="background-color:rgb(23, 12, 12);" data-submit="...Sending" value="submit">Submit</button>
               </fieldset><br>
             </form>  

视图.py

from django.shortcuts import render,redirect
from django.contrib.auth.models import User
def register(request):
    name=request.POST['name']
    email=request.POST['email']
    phone_number=request.POST['phone_number']
    account=request.POST['account']
    message=request.POST['message']


    user=User.objects.create_user(name=name)
    print("we wil call back you")
    return redirect('/')

url.py

from django.urls import path
from django.views import View

from .import views


urlpatterns = [
        path('',views.index,name='index'),
        path('contact/', views.contact,name='contact'),
        path('ideagained/',views.ideagained,name='ideagained'),
        path('idea/',views.idea,name='idea'),
        path('ouridea/',views.ouridea,name='ouridea'),
        path('aboutpage/',views.aboutpage,name='aboutpage'),
        path('register/',views.register,name='register')
        
]

django django-models django-views django-forms django-templates
1个回答
0
投票

改变

  <form action="register" method="POST" onsubmit="register">

  <form action="register/" method="POST" onsubmit="register">

这应该可以解决问题iirc

© www.soinside.com 2019 - 2024. All rights reserved.