Home » Odeon Blogs » Tudor, UI/UX Maestro »

Django Test Client [quick tip]

Django Test Client [quick tip]

While using the Django Test Client, sometimes views need to access request.META['HTTP_HOST'].

Sometimes the views need to retrieve request.META['HTTP_HOST']. This key is not available by default in Django's Test Client. Here's an example on how to enable it:

  1. host = 'django.testserver'
  2. client_providing_host = Client(HTTP_HOST=host)
  3. response = client_providing_host.get('/test_client/my_view/')

The default Django TestCase already contains an instance of the Test Client. Here's how to overwrite it:

  1. def setUp(self):
  2. self.client = Client(HTTP_HOST = "django.testserver")


Categories: Django tdd



Leave a Comment :

(required)


(required)




(required)




(required)






Leave a Comment


Page generated in: 0.14s