views.py
class viewLit(TemplateView):
def get(self, request, strategy=None):
circuit_id = self.request.query_params.get('circuitid', None)
urls.py
path('viewlit/', viewlit.as_view(), name='viewlit')
search_custom.html
<td>
<a href="{% url viewlit %}?circuitid={{ circuit.circuitid }}">
{{ circuit.circuitid }}
</a>
</td>
''' this is an example using a query parameter
the url in urls.py does not need to include this parameter as a slug
the view is able to get the parameter by key name (the same way you get a key from a dict)
the <a></a>tag is formatted to create the url ex (127.0.0.1/foo/) query parameters are everything following the ?
so as you can do something like this 127.0.0.1/foo/?field1=a&field2=b&field3=c
I am not sure if this is the better than your solution but this should work. As well you can add a redirect in viewlit to a different page if
circuit_id does not exist.
'''
On Wed, Sep 25, 2019 at 1:09 PM Patrick Carra <pcarra.pc@gmail.com> wrote:
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.pyurlpatterns = [path('viewLit/', include('viewLit.urls')),]myapp/viewLit/urls.pyurlpatterns=[path('viewLit/circuitid.id', views.viewLit, name='viewLit'),]views.pydef viewLit(request, circuitid):#display records fields herereturn 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.
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/CAE_sR8sFWS_rjXZq6JtUTjpz%3Drzauduq%2BTkWwJvNToK5SgxSuA%40mail.gmail.com.
No comments:
Post a Comment