Reputation: 89
Im trying to pass an id in my URL, it's created in the js and I need to pass it in my render so I can use it in a Jquery on the new page. is this possible?
JS
results ="'results/"+this.pk+"'";
urls
url(r'^personnel/results/(\d*)/$', 'resource.views.personnel_results'),
resultant URL /personnel/results/1/
and my view
def personnel_results(request):
return render(request, 'personnel-results.html',)
Upvotes: 0
Views: 121
Reputation: 599876
You say you want to pass it, but you have avoided doing that in your view. The third parameter to render
, which you explicitly miss out, is the dictionary of keys and values to pass to the template. You need to accept the variable in your view, and pass it in the context.
def personnel_results(request, pk):
return render(request, 'personnel-results.html', {'pk': pk})
This is well covered in the tutorial - you should go back and do that.
Upvotes: 1