I have a django view with html template with a form and a few buttons. When one of the buttons is pressed it sends a get request with a query param and depending on this param I render the page again but with different json paramethers. However I can’t return the webpage with a second return.
This is the important code of the view for the question. I also tried this without return, but it doesn’t work either. I tried using JsonResponce, but no success:
def card(request):
cur_rk = 0
if request.method == 'GET':
if request.GET.get('C', '') == '-1':
q1 = "SELECT MAX(RK) AS L_RK FROM B_DATA;"
with connection.cursor() as cursor:
cursor.execute(q1)
val = cursor.fetchall()
cur_rk = val[0][0]
return render(request, "card.html", get_db_data(cur_rk))
return render(request, "card.html", get_db_data(cur_rk))
Here is the html code if it might help you:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create new card</title>
</head>
<body>
<div class = "enter_data">
<form action = "" method="POST">{% csrf_token %}
<div class = "base">
<h2>Базови данни</h2>
<input type="number" class="field" placeholder="Enter RK" value = {{RK}} name="RK">
<input type="text" class="field" placeholder="Enter RN" value = {{RN}} name="RN">
<input type="text" class="field" placeholder="Enter Marka" value = {{Marka}} name="Marka">
<input type="text" class="field" placeholder="Enter Model" value = {{Model}} name="Model">
<input type="number" class="field" placeholder="Enter G_PR" value = {{G_PR}} name="G_PR">
<input type="number" class="field" placeholder="Enter KM" value = {{KM}} name="KM">
<input type="text" class="field" placeholder="Enter Kupe" value = {{Kupe}} name="Kupe">
<input type="text" class="field" placeholder="Enter Rama" value = {{Rama}} name="Rama">
<input type="text" class="field" placeholder="Enter Dvigatel" value = {{Dvigatel}} name="Dvigatel">
<textarea class="field" placeholder="Enter Descr" name="Descr">{{Descr}}</textarea>
<textarea class="field" placeholder="Enter Problem" name="Problem">{{Problem}}</textarea>
<input type="date" class="field" placeholder="Enter R_DATA" value = {{R_DATA}} name="R_DATA">
</div>
<div class = "client">
<h2>Данни за клиента</h2>
<input type="text" class="field" placeholder="Enter ime" value = {{ime}} name="ime">
<input type="text" class="field" placeholder="Enter telefon" value = {{telefon}} name="telefon">
</div>
<button type = "submit" class = "btn">Add card</button>
</form>
</div>
<div class = "control_btns">
<button id="first" onclick="getData(0)"><<</button>
<button id="previous" onclick="getData({{RK}}-1)"><</button>
<button id="next" onclick="getData({{RK}}+1)">></button>
<button id="last" onclick="getData(-1)">>></button>
</div>
<script>
function getData(card) {
let url = 'http://127.0.0.1:8000/card/?C=' + card.toString();
fetch(url);
}
function greet() {
console.log('Hey there clicker!');
}
</script>
</body>
</html>
ViktorAlexiev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.