AttributeError 'tuple' object has no attribute 'get'

前端 未结 3 630
日久生厌
日久生厌 2020-12-30 04:09

I have a Django application. But i can\'t an error that i have been struggling with for some time now.

Exception Value: \'tuple\' object has no attribute \'g         


        
相关标签:
3条回答
  • 2020-12-30 04:37

    You are returning a tuple here:

    elif retailer_pk:
        return (request, 'page-retailer-single.html', {
            "products": products,
            "sorting": filt["sorting"],
            "filtering": filt["filtering"],
            "retailer": retailer,
        })
    

    Did you forget to add render there perhaps:

    elif retailer_pk:
        return render(request, 'page-retailer-single.html', {
            "products": products,
            "sorting": filt["sorting"],
            "filtering": filt["filtering"],
            "retailer": retailer,
        })
    
    0 讨论(0)
  • 2020-12-30 04:52

    Even taking the commas of the views is as simple of a solution

    as-in this

    def home(request):
        return render(request, 'index.html')
    
    def hire(request):
        return render(request, 'hire.html')
    
    def handler400(request, exception):
        return render(request, '400.html', locals())
    
    def handler403(request, exception):
        return render(request, '403.html', locals())
    
    def handler404(request, exception):
        return render(request, '404.html', locals())
    
    def handler500(request, exception):
        return render(request, '500.html', locals())
    

    Rather than this

    def home(request):
        return render(request, 'index.html'),
    
    def hire(request):
        return render(request, 'hire.html'),
    
    def handler400(request, exception):
        return render(request, '400.html', locals()),
    
    def handler403(request, exception):
        return render(request, '403.html', locals()),
    
    def handler404(request, exception):
        return render(request, '404.html', locals()),
    
    def handler500(request, exception):
        return render(request, '500.html', locals())
    
    0 讨论(0)
  • 2020-12-30 04:56

    There is an extra comma "," at the end of return function in views.py

    return render(request, 'index.html',{}), #incorrect
    

    return render(request, 'index.html',{}) #correct
    
    0 讨论(0)
提交回复
热议问题