Skip to content
Advertisement

Input default values not Displaying in Django through post method

i am working on project in which i have to used python to make blind person to access their account so when they speak there name i want to display it on input field in forms using djangomy view for register

And beolow is my html code in which i have used ajax to make post request to server

    <form action="" method="post" >

        <div class="form-group" align="center">

              <input type="text" name="Email" class="form-control"  value="{{ email }}" readonly placeholder="Email Id" id="myNumber" >
        </div>
          
           </br>

        <a type="submit" class="btn btn-success btn-lg rounded-pill" href='{% url 'menu' %}' >Submit</a>
        </form>


  </div>
###### here i have used id to change default input value####### document.getElementById(‘myNumber’).value = “{{ email }}”; ###### here is the function to make post call ####### function SendPostRequestHome(event){ $.ajax({ url: “{% url ‘register’ %}”, method:”POST”, data: { ‘csrfmiddlewaretoken’: ‘{{ csrf_token }}’}, success: function (data) { if(data.result == ‘success’){ window.location = “{% url ‘menu’ %}”; } else if(data.result == ‘failure’){ window.location = “{% url ‘home’ %}”; } } }); }

but when i run it work fine but it doesnt display anything on the input field it take input and save it in email variable if print it shows it but not displaying in input field plz answer

Advertisement

Answer

You are assigning value to context dictionary on POST method so in GET method the dictionary is empty so you are sending None in your register view function to the input page. You should take care of the GET method and fill the values according to it.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement