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:
- host = 'django.testserver'
- client_providing_host = Client(HTTP_HOST=host)
- 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:
- def setUp(self):
- self.client = Client(HTTP_HOST = "django.testserver")


![Share Django Test Client [quick tip] on twitter](http://twitter-badges.s3.amazonaws.com/twitter-b.png)
Leave a Comment :
Leave a Comment