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

I am sure that many Django developers should face this problem when using social-auth. Initially, when you develop it, you would like to test it on your local server, therefore, you would redirect the domain name in your etc / hosts.

I came to this in the documentation:

https://github.com/omab/django-social-auth#facebook

If you determine the redirect URL on the Facebook settings page, be sure not to define http://localhost:8000 , because it will not work when testing. Instead, I define http://myapp.com and configure the mapping to / etc / hosts or using dnsmasq.

From my understanding, you cannot define any ports in / etc / hosts.

Therefore, defining this entry:

 127.0.0.1 example.com 

still not getting to my Django server, which runs on 127.0.0.1:8000.

How do you do this?

Thanks,

+6
source share
3 answers

I solved the redirection problem by following these steps: https://serverfault.com/questions/397364/how-to-setup-named-virtual-hosts-in-nginx

In short, you need an entry in / etc / hosts, since I have a plus nginx proxy in between.

0
source

Everyone says: “Add example.com to your host file ...”, but you should not mention that after starting the server you should use example.com:8000. Here are the more detailed steps that worked for me:

In linux:

  • open terminal
  • sudo gedit (or replace gedit with a text editor)
  • Open the etc / hosts file
  • add 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 file
  • start your django dev server - python manage.py runningerver
  • open a browser and go to example.com:8000 (this gives the correct answer to google and other sites that will not work with 127.0.0.1 or localhost).
  • You should see the homepage of your django site.
  • Go to the social site you want to connect to and configure your customer 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 / identifier settings and paste into your SETTINGS.py file
  • Your dev server should now work!

I know this is an older post, but I could not find any steps anywhere. Add clarification if necessary, as I am not an expert on this.

+3
source

Install fiddler . After installation, go to Tools> Hosts.

Then you can map from 127.0.0.1:8000 to mysite.com

0
source

Source: https://habr.com/ru/post/917728/


All Articles