Django POST request empty form HTML form

cph2117

For some reason request.body and request.POST are both empty when I attempt to submit a simple HTML form.

The HTML is:

<div id="signup">
      <h1>Sign Up for Free</h1>

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

          <div class="top-row">
            <div class="field-wrap">
              <label>
                First Name<span class="req">*</span>
              </label>
              <input type="text" required autocomplete="off" />
            </div>

            <div class="field-wrap">
              <label>
                Last Name<span class="req">*</span>
              </label>
              <input type="text"required autocomplete="off"/>
            </div>
          </div>

          <div class="field-wrap">
            <label>
              Email Address<span class="req">*</span>
            </label>
            <input type="email"required autocomplete="off"/>
          </div>

          <div class="field-wrap">
            <label>
              Set A Password<span class="req">*</span>
            </label>
            <input type="password"required autocomplete="off"/>
          </div>

          <button type="submit" class="button button-block"/>Get Started</button>

      </form>

    </div>

And the endpoint is:

@api_view(['GET', 'POST'])
def user_register(request):
    if request.method == 'GET':
        return render(request, 'authentication.html')
    elif request.method == 'POST':
        print("Register")
        print request.body
        print request.POST
    else:
        return render(request, '404.html')
Exprator
<div id="signup">
      <h1>Sign Up for Free</h1>

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

          <div class="top-row">
            <div class="field-wrap">
              <label>
                First Name<span class="req">*</span>
              </label>
              <input type="text" name="first_name" required autocomplete="off" />
            </div>

            <div class="field-wrap">
              <label>
                Last Name<span class="req">*</span>
              </label>
              <input type="text" name="last_name" required autocomplete="off"/>
            </div>
          </div>

          <div class="field-wrap">
            <label>
              Email Address<span class="req">*</span>
            </label>
            <input type="email" name="email" required autocomplete="off"/>
          </div>

          <div class="field-wrap">
            <label>
              Set A Password<span class="req">*</span>
            </label>
            <input type="password" name="password" required autocomplete="off"/>
          </div>

          <button type="submit" class="button button-block"/>Get Started</button>

      </form>

    </div>

use this code as in the html you were not passing name attrribute

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

HotTag

Archive