python

I am sure many Django developers must come across this issue when using the social-auth. Initially when you develop it, you would like to test it on your local server, hence you would redirect the domainname in your etc/hosts.

I came along this in the documentation:

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

If you define a redirect URL in Facebook setup page, be sure to not define http://localhost:8000 because it won't work when testing. Instead I define http://myapp.com and setup a mapping on /etc/hosts or use dnsmasq.

From my understanding you can not define any ports in /etc/hosts.

Hence defining this entry there:

127.0.0.1       example.com

still doesn't hit my Django server that runs at 127.0.0.1:8000.

How do you guys do this?

Thanks,


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.


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

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


    Install fiddler. Once installed, go to tools > Hosts.

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

    链接地址: http://www.djcxy.com/p/10846.html

    上一篇: Textmate,从项目搜索中排除文件(类型?)

    下一篇: 蟒蛇