0

I have a 'a tag' such like this.

<a href="{% 'mains:index' %}" name="getData">button</a>

If I click this button, i want to send parameter name "getData" like below, but it does not work.

views.py

def index(request):
  result = request.GET.get('getData')

how can I get prameter from template by a tag, and how can using in views.py? return = render(request, 'mains/index.html', 'result':result)

if my question is confused, just ask me plz.

1

2 Answers 2

0

You can use builtin url for this. <a href="{% url 'index' %}?getData=True">button</a> should work. But I highly recommend you to use forms to send data from html to view with an elegant format as Hisham___Pak mentioned in the comment.

1
  • Good news, Can you accept the answer to help others to see the answer easily? Commented May 15, 2020 at 18:03
0

try like this

put url.py file view like add name = 'index'

{% url 'index' %}" name="getData"

2
  • I can't understand Is it matter name argument? path('index/', views.index, name="index"), I already write like above
    – Gamrom
    Commented May 13, 2020 at 7:26
  • another answer really help for me. Sorry about my explanation and thank you for your help, either.
    – Gamrom
    Commented May 13, 2020 at 10:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.