【问题标题】:How do a change a dynamic localhost port?如何更改动态本地主机端口?
【发布时间】:2019-01-20 04:54:31
【问题描述】:

Mismatch

我目前正在本地网络服务器上测试我的网站。

每次运行 python3 manage.py 单元测试时,本地主机端口 localhost:[port] 都会不断变化。

由于 localhost:port 在每次测试中都发生变化,它无法将 url [localhost:'port'] 与我在 Oauth 凭据中输入的重定向 url 匹配。

我如何能够运行我的单元测试并让浏览器每次都使用某个端口?

我目前正在关注 taskbuster django 教程 http://www.marinamele.com/user-authentication-with-google-using-django-allauthtaskbuster

如果您在该页面上向下滚动到以下部分 “表明http://localhost:8081 的重定向 URI 无效。这是因为我们注册了一个不同的 url,http://127.0.0.1:8000,而不是测试使用的那个。” 然后我的问题就会变得明显。

总结

1.我已注册回调地址为http:127.0.0.1:8081

  1. 每次我运行单元测试时,Web 服务器都会在以下 'http:127.0.0.1:53000' 或该数字的变体上运行。

    1. 如何让测试在指定端口上运行。

【问题讨论】:

标签: python django localhost port


【解决方案1】:

解决方案:

经过一些研究并询问了一些 Django 用户 - 解决方案是在测试类下方添加端口 = 8010。

class TestGoogleLogin(StaticLiveServerTestCase):

    fixtures = ['allauth_fixture']
    port = 8010

    def setUp(self):
        "CODE"

【讨论】:

    猜你喜欢
    • 2012-06-12
    • 1970-01-01
    • 2018-05-10
    • 1970-01-01
    • 2016-04-12
    • 2020-07-24
    • 2015-02-26
    • 1970-01-01
    • 2020-01-27
    相关资源
    最近更新 更多