Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

101
Vistas
is it possible to redirect to another page with id from the previous page?

enter image description here

So as you can see on a page I have Shop name and it's adress. Moreover I have an edit function on views.py:

def update_shop(request, id):
    context = {}

# * fetch the object related to passed id
    obj_shop = get_object_or_404(VideoLibrary, id=id)


# * pass the object as instance in form
    form_shop = VideoLibraryForm(request.POST or None, instance=obj_shop)


# * save the data from the form and
# * redirect to detail_view

    if form_shop.is_valid():
        form_shop.save()
        return HttpResponseRedirect('/main/')

    context['form_shop'] = form_shop

    return render(request, 'update/update_shop.html', context)

urls.py:

...
path('list_view/', views.list_view, name='list_view'),
path('shop/<id>/update', views.update_shop, name='update_shop'),

The image is on a different page ('lilst_view') and the issue is - I need to place a button on this page and redirect to the update page in order to edit certain shop names for example. To do this as I suppose I need to get somehow the id of the object. Does anybody know how to do it?

list_view.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div class="main">
      {% for data in library_dataset %} Shop name:
      <br />
      <br />
      {{ data.shop_name }} <br />
      {{ data.adress }} <br />

      {% endfor %}
    </div>
  </body>
</html>

views.py (def list_view):

def list_view(request):

    context = {}

    context['library_dataset'] = VideoLibrary.objects.all()

    return render(request, 'app/list_view.html', context)
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

#list_view.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div class="main">
      {% for data in library_dataset %} 
      Shop name:
      <br />
      <br />
      {{ data.shop_name }} <br />
      {{ data.adress }} <br />
      <td><a href="{% url 'update_shop' data.id  %}">
    <button type="button" class="btn btn-primary">Edit Shop Details</button>
    </a>
</td>

      {% endfor %}
    </div>
  </body>
</html>
about 4 years ago · Juan Pablo Isaza Denunciar

0

in this case you can do it in Django by simply useing redirect() method with parameters, for example

return redirect('some-view-name', parameter_name='par_value')

and in a tag put <a href={% url 'view_name' desired_id %}

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda