Skip to content Skip to sidebar Skip to footer

Python-django Url With Two Slugs

Hello I have a problem while I am trying two slugs in one url. I have: html file:

Solution 1:

This is how I fixed it:

in the html file:

<h4><ahref="{% url 'data:inspection_detail' slug=plant.slug inspection_id=inspection.id %}" >{{inspection.name}}</a></h4>

my views.py

definspection_detail(request,slug, inspection_id):
    inspection = get_object_or_404(Inspection, pk=inspection_id)
    plant = get_object_or_404(Plant, slug=slug)
    recordings = Recording.objects.filter(inspection__id=inspection_id)
    template = 'data/inspection_detail.html'
    context = {'plant': plant, 'inspection': inspection, 'recordings':recordings,}
    return render(request, template, context)

and my url file:

url(r'^plants/(?P<slug>[-\w]+)/inspection(?P<inspection_id>[0-9]+)/create_recording$', views.create_recording, name='create_recording'),

Post a Comment for "Python-django Url With Two Slugs"