【问题标题】:django not responding via submit in frontend using post request in formdjango 没有通过使用表单中的 post 请求在前端提交响应
【发布时间】:2019-08-29 11:37:16
【问题描述】:

前端没有通过表单响应django函数调用,表单标签或位置有什么错误,我无法得到它。

<form method="post" action="choose" class="login100-form validate-form" id="loginFrm">
                        {% csrf_token %}
                        <span class="login100-form-title p-b-59">
                            Sign In
                        </span>
                        <div class="wrap-input100 validate-input" data-validate = "Valid email is required: ex@abc.xyz">
                            <!-- <span class="label-input100">Email</span> -->
                            <input class="input100" type="text" name="email" placeholder="Email address...">
                            <span class="focus-input100"></span>
                        </div>
                        <div class="wrap-input100 validate-input" data-validate = "Password is required">
                            <!-- <span class="label-input100">Password</span> -->
                            <input class="input100" type="text" name="pass" placeholder="Password">
                            <span class="focus-input100"></span>
                        </div>

                        <div class="flex-m w-full p-b-33">
                            <div class="contact100-form-checkbox">
                                <span class="txt1">
                                    <a href="javascript:void(0)" class="txt2 hov1" id="goForgot">
                                        Forgot Password?
                                    </a>
                                </span>
                            </div>
                        </div>

                        <div class="container-login100-form-btn">
                            <div class="wrap-login100-form-btn">
                                <div class="login100-form-bgbtn"></div>
                                <button type="submit" class="login100-form-btn">
                                    Sign In
                                </button>
                            </div>

                            <a href="javascript:void(0)" class="dis-block txt3 hov1 p-r-30 p-t-10 p-b-10 p-l-30" id="goSignup">
                                Sign Up
                                <i class="fa fa-long-arrow-right m-l-5"></i>
                            </a>
                        </div>
                    </form>

这里是通过表单标签调用的 django 函数

def choose(request):
    v = request.POST['email']
    print(v)
    return render(request, 'smart-choose.html')

【问题讨论】:

  • 在表单的action中,不能指定Python函数,需要指定URL

标签: html django forms http-post


【解决方案1】:

如果你的网址像http://127.0.0.1:8000/choose/,那么试试这个

<form method="post" action="/choose" class="login100-form validate-form" id="loginFrm">

def choose(request):
    if request.method == 'POST':
        v = request.POST.get('email')
        print(v)
        return render(request, 'smart-choose.html')

【讨论】:

    猜你喜欢
    • 2020-02-28
    • 2018-03-09
    • 1970-01-01
    • 2017-02-18
    • 2018-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多