[Fixed]-How to retrive the object data by using it's id in Django in template file (HTML file)?

1👍

If you are using Django’s own template system:

You can access variables, which you have passed into the context dictionary(in your view file), simply by using {{ variable_name }} tag in your template file.

Update:

You need to retrieve object from your database in your view, like you did it in your index view. If you wan to retrieve single object from you databse in detail view, you can do this like this:

def detail(request, car_id):
    car = Car.objects.get(pk=car_id)
    context = {
        'car': car
    }
    return render(request, 'CarBank/details.html', context)

Then simply call {{ car }} in your template

read more here

Leave a comment