Search code examples
pythondjangopython-3.xdjango-2.1

django unit test client response has empty request


in my test I do:

self.client.get('/')

in my template I access:

request.LANGUAGE_CODE

in the browser it works fine with the Django client I get

Failed lookup for key [LANGUAGE_CODE] in ''

From the output I believe that the request is not set in the client.

Similar Issue that didn't help me


Solution

  • I found the error myself:

    The test client was working just fine. Some of the sites were really not working.

    In my views.py I had the following bug:

    wrong code:

    return render(some_other_view, 'page.html')

    correct code:

    return render(request, 'page.html')