Answer the question
In order to leave comments, you need to log in
How to send a request using the POST method?
I am developing a website in django.
There is the following form:
<form action="/external/" method="POST">
<div id="profile"></div>
<input type="button" value="добавить" onclick="addInput()">
<input type="button" value="создать массив" onclick="func()">
<input type="submit" value="Выполнить">
</form>
let i = 0;
function addInput() {
if (i < 5) {
i = i + 1;
let profile = document.getElementById('profile');
let div = document.createElement('div');
div.innerHTML = '<label>Значение:</label> <input type="text" name="items" id="box' + (i + 1) + '">';
profile.append(ip);
}
}
function func() {
let box = document.getElementsByName('items');
let items = [];
for(n=0; n < box.length; n++){
let content = box[n].value
items.push(content)
}
console.log(items)
}
def external(request):
items = request.POST.getlist('items')
run([sys.executable, 'codetest.py', items])
return render(request, 'main/test.html')
Answer the question
In order to leave comments, you need to log in
name="items[]"
Then the entire value of items will be passed as an array.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question