Reputation: 533
I would really appreciate if you can give a hand with this. What I'm trying to do it's just to render the value of some text label, but it gives me the token.
I'm learning django I hope you can comprehend.
The result of this is:
eee 12121 csrfmiddlewaretoken yYvl3neQZSP33vSRNto3FUFa88AMeFQi
view.
def test(request):
if request.method == "POST":
response = ''
for key, value in request.POST.items():
response += '%s %s\n' % (key, value)
return HttpResponse(response)
return render(request, 'datos2.html')
datos2.
<form action="/test" method="post"> {% csrf_token %}
<input type="text" name="eee">
<input type="submit">
</form>
<p>ADD VALUE</p>
<button onclick="myFunction()">ADD</button>
<script>
function myFunction() {
var x = document.createElement("INPUT");
x.setAttribute("type", "text");
x.setAttribute("value", "0");
x.setAttribute("name", "eee");
document.body.appendChild(x);
}
</script>
Upvotes: 0
Views: 24
Reputation: 14054
You are looping over all the elements in the POST array in this snippet of code
for key, value in request.POST.items():
response += '%s %s\n' % (key, value)
I believe, if i understand your question, that what you are after is simply request.POST.get('eee')
Upvotes: 1