django-social-auth : How to redirect example.com to 127.0.0.1:8000?

Everyone says, "add example.com to your hosts file..." but neglects to mention that you should use example.com:8000 after starting the runserver. Here are more detailed steps that worked for me:

On linux:

  • open a terminal
  • sudo gedit (or replace gedit with the text editor of choice)
  • Open the etc/hosts file
  • add a line: 127.0.0.1 example.com (if you already have a line starting with 127.0.0.1 you can leave it - https://serverfault.com/questions/231844/is-it-safe-to-add-additional-127-0-0-1-entries-to-etc-hosts)
  • save the file
  • start your django dev server - python manage.py runserver
  • open a browser and go to example.com:8000 (this gives the correct callback to google and other sites that will not work with 127.0.0.1 or localhost)
  • You should see the home page of your django site.
  • Go to the social site you want to connect with and set up your client ID, using example.com as the website name. For example, the callback url for google is http://example.com:8000/complete/google-oauth2/
  • Copy the appropriate key/id settings and paste into your SETTINGS.py
  • Now your dev server should work!

I know this is an older post, but I could not find the complete steps anywhere. Please add clarifications if necessary as I am not an expert with this.