【问题标题】:Django Heroku PortingDjango Heroku 移植
【发布时间】:2022-01-09 10:17:23
【问题描述】:

尝试为公共 url 设置 Django 配置。

所以我先运行了这个。

$ echo "web: python manage.py runserver 0.0.0.0:\$PORT" > Procfile
$ git add Procfile
$ git commit -m "Specify the command to run your project"

在 Procfile 中:

web: python manage.py runserver 0.0.0.0:\$PORT 
release: python manage.py migrate

在 Settings.py 中:

PORT = os.getenv("PORT", default="5000")
# SECURITY WARNING: don't run with debug turned on in production!
# DEBUG = True

DEBUG = os.environ.get('DJANGO_DEBUG', '') != 'False'

ALLOWED_HOSTS = ["url"]

在环境中:

PORT=5000
SECRET_KEY=value

正在使用上述命令并得到了

(portfolio) PS C:\Users\arund\Desktop\Code\Django\portfolio-project> heroku config:get PORT
5000
(portfolio) PS C:\Users\arund\Desktop\Code\Django\portfolio-project> heroku local
[OKAY] Loaded ENV .env File as KEY=VALUE Format
3:08:10 PM web.1 |  CommandError: "0.0.0.0:\$PORT" is not a valid port number or address:port pair.
[DONE] Killing all processes with signal  SIGINT
3:08:10 PM web.1 Exited with exit code null

我还使用了不带反斜杠和 $ 的 $PORT。我将如何从这里着手使公共 url 工作。

CommandError: "0.0.0.0:PORT" is not a valid port number or address:port pair does the same thing. 

web: python manage.py runserver 0.0.0.0:5000 将适用于本地

【问题讨论】:

    标签: django windows heroku


    【解决方案1】:

    使用 gunicorn 通过 Heroku 为您的 Web 应用程序提供服务,如下所述:

    https://devcenter.heroku.com/articles/python-gunicorn

    关于您的错误,我认为您在技术上是在转义 $,因此它没有扩展变量。

    尝试删除\,或者,出于调试目的,通过硬编码您希望在$PORT 中的端口,看看这是否有效,如果有效,我想您需要设置@987654325 @env 变量。

    【讨论】:

    • 我使用的是 Windows 机器。
    • 然后硬编码端口号?
    • 尝试在单个 config var switch DJANGO_DEBUG 后在本地和 prod 之间切换。所以 localhost:5000 可以工作,然后在我将 DJANGO_DEBUG 设置为 False 之后的站点。
    • @Arundeep 最后的解决方案是什么?
    • procfile.windows 结合其他一些东西
    猜你喜欢
    • 1970-01-01
    • 2011-12-22
    • 1970-01-01
    • 1970-01-01
    • 2016-11-25
    • 1970-01-01
    • 2019-11-26
    • 2011-02-25
    • 2015-06-26
    相关资源
    最近更新 更多