Wednesday, September 25, 2019

Django - How to add a link to a table that will open another page(django app) from an html template and pass a variable with it.

Hello I have an app that displays some database information in a table.  Inside of the html template I am making an edit link that I want to open another app(page viewLit) while passing a value to it's view.  I have added my code below.  My question is I am unsure of how to make this links url and pass the object data located inside circuit.circuitid along with it.  I haven't been able to find the right way to code this yet and this is just how I thought that this should be done. If anyone has a better idea I am open to suggestions.

search_custom.html(code for link)
{% for circuit in filter.qs %}
<tr>
    <td class="actions">
        <a href="" class ="view-item" title ="View">View</a>
    </td>
    <td>{{ circuit.circuitid }}</td>
</tr>
{% endfor %}

myapp/myapp/urls.py
urlpatterns = [
    path('viewLit/', include('viewLit.urls')),
]

myapp/viewLit/urls.py
urlpatterns=[
    path('viewLit/circuitid.id', views.viewLit, name='viewLit'),
]

views.py
def viewLit(request, circuitid):
    #display records fields here
    return HttpResponse("You are at the viewLit page!")

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d81bf60a-260c-44c1-9c12-e852b51432a9%40googlegroups.com.

No comments:

Post a Comment