I'm trying to get the values out of a form that is not in the forms.py, besides this has a button to add a value, what I want is only to print the values entered on the screen, unfortunately I could not make it work.
Error message
local variable 'response' referenced before assignment
urls
url(r'^test', views.test),
views
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.html
<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>
At the time of executing it I get the following error
local variable 'response' referenced before assignment