I
I
Inga2020-11-26 19:42:06
Django
Inga, 2020-11-26 19:42:06

GET request in Django?

Good evening. I'm doing my little Django project. There is HTML code

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Main</title>
</head>
<body>
<div>
    <h1>Таблица сайтов</h1>
    <table>
        <tr>
          <th>Название</th>
          <th>Описание</th>
        </tr>
        {% for el in sites %}
       <tr>
           <td><a {% if el.url != '' %} href="link/", test = "{{el.url}}"
                  {% else %} onclick="alert('Ошибка. Отсутствует URL.') "LANGUAGE="Javascript" {% endif %}>{{ el.name }}</a></td>
           {% if el.description != '' %}
                <td>{{ el.description }}</td>
           {% else %}
                <td>Отсутствует описание</td>
           {% endif %}
       </tr>
        {% endfor %}
    </table>
</div>

</body>
</html>


I'm trying to get the site url from the link and use it in the make_qr_code function. But my get request is returning empty.
def index(request):
    sites = table.objects.all()
    return render(request,  'main/index.html', {'sites': sites})


def make_qr_code(url):
    s = url.GET.get('test',"")
    output = "<h1>Hello, link is {0}</h1>".format(s)
    return HttpResponse(output)

urls.py
from django.urls import path
from django.conf.urls import url
from . import views

urlpatterns = [
    path('', views.index),
    path('link/', views.make_qr_code, name='qr')
]

Why is this happening, what did I do wrong? Thanks in advance!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question