gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 21:53:30 25 4
gpt4 key购买 nike

我相信许多 Django 开发人员在使用社交身份验证时一定会遇到这个问题。最初当你开发它时,你想在你的本地服务器上测试它,因此你会在你的 etc/hosts 中重定向域名。

我在文档中发现了这一点:

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.

据我了解,您不能在/etc/hosts 中定义任何端口。

因此在那里定义了这个条目:

127.0.0.1       example.com

仍然没有命中运行在 127.0.0.1:8000 的 Django 服务器。

你们是怎么做到的?

谢谢,

最佳答案

每个人都说,“将 example.com 添加到您的主机文件中……”但忽略了在启动运行服务器后应使用 example.com:8000。以下是对我有用的更详细的步骤:

在 Linux 上:

  • 打开终端
  • sudo gedit(或将 gedit 替换为所选的文本编辑器)
  • 打开 etc/hosts 文件
  • 添加一行:127.0.0.1 example.com(如果您已有以 127.0.0.1 开头的行,您可以保留它 - https://serverfault.com/questions/231844/is-it-safe-to-add-additional-127-0-0-1-entries-to-etc-hosts)
  • 保存文件
  • 启动你的 django 开发服务器 - python manage.py runserver
  • 打开浏览器并转到 example.com:8000(这会向 google 和其他无法使用 127.0.0.1 或本地主机的网站提供正确的回调)
  • 您应该会看到您的 Django 站点的主页。
  • 转到您要连接的社交网站并设置您的客户端 ID,使用 example.com 作为网站名称。比如google的回调url是http://example.com:8000/complete/google-oauth2/
  • 复制适当的 key /ID 设置并粘贴到您的 SETTINGS.py 中
  • 现在您的开发服务器应该可以正常工作了!

我知道这是一篇较旧的帖子,但我无法在任何地方找到完整的步骤。如有必要,请添加说明,因为我不是这方面的专家。

关于python - django-social-auth : How to redirect example. com 到 127.0.0.1 :8000?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10970115/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com