Currently, I am using this code to render a page:
return render(request, 'appname/bundles_edit.html', context)
This works fine. However, I would like to send two integers to my path:
path('bundles/<int:bundle_template_number>/<int:bundle_id>/', views.bundles_edit, name='bundles_item'),
How would I insert those two integers in my return render statement?
Edit: Views Functions:
def bundles(request):
context = {}
if 'bundle_to_edit' in request.POST:
bundle = request.POST['bundle_to_edit']
instance_as_list = bundle.split(',')
template_number = instance_as_list[0]
template_id = instance_as_list[1]
return render(request, 'contractor/bundles_edit.html' + '/' + template_number + '/' + template_id,, context)
return render(request, 'contractor/bundles.html, context)
def bundles_edit(request):
context= {}
return render(request, 'contractor/bundles_edit.html', context)
I know the first return render is wrong, but I am not sure how to do it properly.
Edit 2: Updated code.
def bundles(request):
if 'bundle_to_edit' in request.POST:
bundle = request.POST['bundle_to_edit']
instance_as_list = bundle.split(',')
template_number = instance_as_list[0]
bundle_id = instance_as_list[1]
context['bundle_template_number'] = template_number
context['bundle_id'] = bundle_id
return render(request, 'contractor/bundles_edit.html', context)
return render(request, 'contractor/bundles.html, context)
def bundles_edit(request, bundle_template_number, bundle_id):
context= {}
context['bundle_template_number'] = bundle_template_number
context['bundle_id'] = bundle_id
return render(request, 'contractor/bundles_edit.html', context)
urls.py:
path('bundles/<int:bundle_template_number>/<int:bundle_id>/', views.bundles_edit, name='bundles_item'),
Everything works at this point, it just leaves me with the browser URL as: /contractor/bundles/ instead of /contractor/bundles/1/8/
bundlesview you want to redirect tobundles_editview?render()andredirect()and the template path with the url arguments. You certainly want to read the doc about urls and thereverse()function (docs.djangoproject.com/en/3.0/ref/urlresolvers/#reverse)