0

I have a template like below:

 <a href={{j}}>
  <img src="{{k}}" class="img-responsive img-rounded" data-toggle="modal" 
   data-target="#myModal" style="width:350px;height:200px;">
</a>

I have a function like below:

 def function_url(request):
   a = get_the_value_of_{{j}}  # how to get the value of {{j}}

How to send the {{j}} value to the function (function_url) when user clicks on the photo url either with ajax or django?

Kryštof Řeháček
  • 1,965
  • 1
  • 16
  • 28
honda
  • 31
  • 9

1 Answers1

2

You should create new path in the urls.py. Assuming you use path from Django 2.0, if not use url.

urls.py

urlpatterns = [
    ...
    path('clicked-on-img/<str:value>/', views.function_url, name='url-name'),
    ...
]

views.py

def function_url(request, value):
    a = value # got it!

and in the template use it as

<a href="{% url 'url-name' value='img1' %}">
    ...

EDIT: changed double quotes to single quotes in the <a ... value='img1'>

Kryštof Řeháček
  • 1,965
  • 1
  • 16
  • 28