试图为公共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"]在env.:
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,没有反斜杠和$。从这里开始我该怎么做才能让公众的网址发挥作用。
CommandError: "0.0.0.0:PORT" is not a valid port number or address:port pair does the same thing. 网站: 0.0.0.0:5000将适用于本地manage.py
发布于 2021-12-02 23:29:32
使用gunicorn通过Heroku为您的web应用程序服务,如下所述:
https://devcenter.heroku.com/articles/python-gunicorn
关于您的错误,我认为您在技术上是在转义$,因此它没有扩展变量。
尝试删除\,或者为了调试目的,通过硬编码$PORT中的端口来查看这是否有效,并查看它是否有效,如果有效,我想您需要设置$PORT env变量。
发布于 2022-06-28 18:32:20
我花了大约两个小时才终于弄清楚到底发生了什么,这就是为什么我要放弃这个答案给任何可能有帮助的人。如果您在本地使用Windows (比如vscode上的powershell ),那么$PORT或\$PORT都不会被解析为环境变量。所以你可能想用像5000这样的硬编码的东西来测试。但是由于Heroku操作系统是基于Linux的,所以它是公认的。因此,简而言之,在本地,您可以使用
‘'web: 0.0.0.0:5000’
在推到Heroku之前,请将线路更改为
‘'web: PythonRunserver0.0.0.0:$ manage.py’
(如果没有反斜杠,反斜杠就会在Linux上转义)。
https://stackoverflow.com/questions/70207654
复制相似问题