Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用Heroku[获取请求,无限加载]部署Django REST API_Python_Django_Git_Heroku_Deployment - Fatal编程技术网

Python 使用Heroku[获取请求,无限加载]部署Django REST API

Python 使用Heroku[获取请求,无限加载]部署Django REST API,python,django,git,heroku,deployment,Python,Django,Git,Heroku,Deployment,所以我现在正在做一个项目,看起来像: - project-d/ - api/ - app/ - web/ 我们的重点是首先将api/文件夹中的所有内容部署到Heroku上。这就是Django项目所在地 我迄今为止采取的步骤: 在Heroku上创建了一个新节点 添加了环境变量(包括:禁用\u COLLECTSTATIC=1,因为我没有静态文件)。我的数据库(PostgreSQL)运行在Docker容器内的数字海洋液滴上(港口是开放的) 将git项目连接到Heroku(Heroku登

所以我现在正在做一个项目,看起来像:

- project-d/
  - api/
  - app/
  - web/
我们的重点是首先将
api/
文件夹中的所有内容部署到Heroku上。这就是Django项目所在地

我迄今为止采取的步骤:
  • 在Heroku上创建了一个新节点
  • 添加了环境变量(包括:
    禁用\u COLLECTSTATIC=1
    ,因为我没有静态文件)。我的数据库(PostgreSQL)运行在Docker容器内的数字海洋液滴上(港口是开放的)
  • 将git项目连接到Heroku(
    Heroku登录
    Heroku git:remote-一个特殊公园
  • settings.py
    中的
    ALLOWED\u HOSTS
    中添加了Heroku项目的域(请参见此处的文件:)
  • 我使用了Pipfile,所以不需要requirements.txt
  • 添加了runtime.txt,其中包含
    python-3.7.6
  • 添加了包含以下内容的程序文件:gunicorn specialpark.wsgi--pythonpath=specialpark--log文件-
  • 现在我将所有内容都推送到Heroku上,因为我们只希望部署子目录,所以我运行了以下命令:
    git subtree push——前缀api/Heroku master
响应

➜  project-d git:(deployment) git subtree push --prefix api/ heroku master
git push using:  heroku master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 284 bytes | 284.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Python app detected
remote: -----> Requirements file has been changed, clearing cached dependencies
remote: cp: cannot stat '/tmp/build_88d222dddd3ed0c8949a8d8032e6beb6/requirements.txt': No such file or directory
remote: -----> Installing python-3.7.6
remote: -----> Installing pip
remote: -----> Installing dependencies with Pipenv 2018.5.18…
remote:        Installing dependencies from Pipfile.lock (7a8381)…
remote: -----> Installing SQLite3
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote: 
remote: -----> Compressing...
remote:        Done: 73.2M
remote: -----> Launching...
remote:        Released v23
remote:        https://special-park.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/special-park.git
   c296867..e786aa7  e786aa7057e186e3da89faef8360c306675ce07d -> master
因此,该应用程序似乎已经部署。所以我打开了Postman,试图向/users/car发送一个GET请求,这样它就会返回该用户的所有汽车

但是当我和邮递员一起发送请求时,请求一直在加载,而且永远不会完成。我两个都试过了

  • https://special-park.herokuapp.com/users/car/
  • https://special-park.herokuapp.com:8000/users/car/
但是它不像在本地运行项目时那样,不会向我发送回复

有人能发现错误吗?这是回购协议,我在
部署
分支机构内部工作:

更新 我添加了两个视图

@api_view(["GET"])
@permission_classes([])
def welcome(request):
    return JsonResponse({ 'msg': 'Welcome to Special Park'})

@api_view(["GET"])
@permission_classes([])
def welcome_user(request):
    user = User.objects.get(id=1)
    return JsonResponse({ 'msg': 'Welcome to Special Park', 'user': user.username })
第一个可行,但第二个失败。所以我知道这和数据库有关。我认为这种联系从未建立。该数据库是一个PostgreSQL数据库,运行在数字海洋液滴上的docker容器内


有人知道为什么这个连接不起作用吗?

原因是,Digital Ocean上的数据库和Heroku应用程序之间从未建立过连接。我删除了Digital Ocean上的数据库,让Heroku为我建立了一个数据库。现在它工作得很好

您是否在浏览器中尝试过,它有点工作,但您在不设置静态方面遇到了问题_ROOT@iklinac我添加了
STATIC\u ROOT
,您可以在
settings.py
(第158行)中看到这一点。我重新部署了,现在正在工作。但当向邮递员提出请求时,它仍然卡在加载中。同样在浏览器中,当我填写有效的用户名和密码时,请求将继续加载,并最终导致应用程序错误。所以naar deze vraag!!!!嘿,来晚了。你的github回购协议已经失效。我听不懂这个问题。你把它搬到别的地方了吗?