django not rendering template in html but as ordinariny textfile on browser

Viewed 39

all my codes are working correctly but showing as text on browser. they are not rendering as an html page

here is what my views is like

    @login_required
def product_list(request, template_name='product/product_list.html'):
    ppix = Profilepix.objects.filter(user=request.user)
    product = Product.objects.filter(username=request.user).order_by('-postdate')
    data = {}
    data['object_list'] = product
    return render(request, template_name, data, {'Profilepix': ppix})
1 Answers

You are passing the Profilepix as a header in the HTTP response. If you want to pass both items to the render(…) function [Django-doc], then you should pass a dictionary with two entries, so:

@login_required
def product_list(request, template_name='product/product_list.html'):
    ppix = Profilepix.objects.filter(user=request.user)
    product = Product.objects.filter(username=request.user).order_by('-postdate')
    data = {
        'object_list': product,
        'Profilepix': ppix
    }
    return render(request, template_name, data) # no fourth item
Related