1

i have html file that contains both login and signup form

 <form method = "POST" enctype="multipart/form-data" > 
       {{ user_form.as_p }}
       {% csrf_token %}
       <input type="text" id="firstname" placeholder="First Name" name = "first_name" required>
       <div class="invalid-feedback">Please enter a valid first name.</div>
       <input type="text" class="input-field" id="lastname" name = "last_name" placeholder="Last Name" required>
       <div class="invalid-feedback">Please enter a valid last name.</div>
    </form>

and a similar login form how to write a single view for both of these forms using buttons i have already seen How can I build multiple submit buttons django form? this but i didn't found useful

def user_login:
    if request.method == 'POST' and request.POST.get('submit') == 'name1':
        pass
    elif request.method == 'POST' and request.POST.get('submit') == 'name2':
        pass

in this how to write else code if request.method not POST for every form

uma_8331
  • 79
  • 5
  • Instead of `request.method.get['submit']` I believe perhaps you want to use `request.POST.get('submit')`? (`request.method` is really a string it does not make sense to use the `get` method there) – Abdul Aziz Barkat Mar 05 '21 at 11:37
  • i mistakenly write that , it also not working can you suggest anysite for that code – uma_8331 Mar 05 '21 at 11:39
  • My bad I just copied from your post. I meant to use the method not index it. I have edited the comment above. – Abdul Aziz Barkat Mar 05 '21 at 11:40

0 Answers0