hi Andreas, On Sunday, May 13, 2018 at 4:12:09 PM UTC+5:30, Andréas Kühne wrote: > > Hi, > > The error is pretty self explanatory. When the test client calls the > django server it uses the hostname of testserver. This works while testing > and also in development mode as long as you have DEBUG=True in your > settings file. > > If you have changed that to False, django will look in the list of > ALLOWED_HOSTS in the settings file (which should be set to the hostnames > that your server allows) - but you shouldn't require it for testing. > > If you have set DEBUG to False and set the ALLOWED_HOSTS setting to the > production server and want to test something with the django test client > you can initialize the client with the following statement: > > client = Client(SERVER_NAME='www.example.com') > > and change to the correct server name. > > Regards, > > Andréas > > 2018-05-13 9:02 GMT+02:00 Avitab Ayan Sarmah <avita...@gmail.com > <javascript:>>: > >> Hi all, >> while going through the dajngo tutorial i stuck while executing a >> code i.e., mentioned below. It is shoeing "Invalid HTTP_HOST header: >> 'testserver'. You may need to add 'testserver' to ALLOWED_HOSTS.". >> >> >> the code is written in python manage.py shell.i.e., >> >> PS C:\Users\AVITABAYAN\mysite> python manage.py shell >> Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit >> (AMD64)] on win32 >> Type "help", "copyright", "credits" or "license" for more information. >> (InteractiveConsole) >> >>> from django.test import Client >> >>> #... >> >>> client = Client() >> >>> #... >> >>> response = client.get('/') >> Invalid HTTP_HOST header: 'testserver'. You may need to add 'testserver' >> to ALLOWED_HOSTS. >> >> please find what is error and comment.Thank you >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django-users...@googlegroups.com <javascript:>. >> To post to this group, send email to django...@googlegroups.com >> <javascript:>. >> Visit this group at https://groups.google.com/group/django-users. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/53313ac7-6840-4ee9-b49b-804f91a045d4%40googlegroups.com >> >> <https://groups.google.com/d/msgid/django-users/53313ac7-6840-4ee9-b49b-804f91a045d4%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > >
-- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0816123f-719d-40b1-a9db-0c06626b1dfa%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.