The href in template and the Url are not working in Django

sonia

I am new to django. I have made a table cell clickable but when i click that cell, nothing happens.

template :

 {% for each in object_list %}
   <tr>                  
   <td id="{{ each.id }}"   data-href="http://127.0.0.1:8000/{{ each.region }}/{{ each.id }}"></td>
   </tr>
 {% endfor %}

needed part of view:

class MeterDetailView(DetailView):
       model = Meter
       template_name = 'meter/specificMeter.html'

       def get_context_data(self, **kwargs):
          pk = kwargs.get('pk',None)
          obj = Meter.objects.get(pk=pk)

url :

    path('<int:region>/<int:pk>/', views.MeterDetailView.as_view(), name='detail')

model :

class Meter(models.Model):
   region   = models.PositiveSmallIntegerField()
   UserId   = models.BigIntegerField(default=0,null=False)

what is wrong?Thank you all.

quqa123

to make the cell that redirects after it's clicked you can use onclick attribute. In your case we would have to change the code a bit:

 {% for each in object_list %}
   <tr>                  
       <td id="{{ each.id }}" onclick="window.location='http://127.0.0.1:8000/{{ each.region }}/{{ each.id}}'"></td>
   </tr>
 {% endfor %}

similar approaches can be found in this question

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related