2017-06-04 76 views
-1

與REST API運行Django應用程序我剛剛創建的帳戶上「Heroku.com」跟着指南中的步驟來創建一個新的Python項目。我在本地克隆了這些文件,並在項目中添加了一個新的應用程序,並創建了一個休息API。我說「rest_framework」我的「settings.py」我能夠在本地運行項目。當我試圖推動修改到Heroku的,它失敗,我得到這個消息:當我從「settings.py」刪除「rest_framework」我可以成功地把我的變化不能在Heroku

Counting objects: 6, done. 
Delta compression using up to 2 threads. 
Compressing objects: 100% (6/6), done. 
Writing objects: 100% (6/6), 632 bytes | 0 bytes/s, done. 
Total 6 (delta 5), reused 0 (delta 0) 
remote: Compressing source files... done. 
remote: Building source: 
remote: 
remote: -----> Python app detected 
remote: -----> Installing requirements with pip 
remote: 
remote: Package django found! 
remote: -----> $ python manage.py collectstatic --noinput 
remote:  Traceback (most recent call last): 
remote:   File "manage.py", line 10, in <module> 
remote:   execute_from_command_line(sys.argv) 
remote:   File "/app/.heroku/python/lib/python3.6/site- 
packages/django/core/management/__init__.py", line 353, in 
execute_from_command_line 
remote:   utility.execute() 
remote:   File "/app/.heroku/python/lib/python3.6/site- 
packages/django/core/management/__init__.py", line 327, in execute 
remote:   django.setup() 
remote:   File "/app/.heroku/python/lib/python3.6/site- 
packages/django/__init__.py", line 18, in setup 
remote:   apps.populate(settings.INSTALLED_APPS) 
remote:   File "/app/.heroku/python/lib/python3.6/site- 
packages/django/apps/registry.py", line 85, in populate 
remote:   app_config = AppConfig.create(entry) 
remote:   File "/app/.heroku/python/lib/python3.6/site- 
packages/django/apps/config.py", line 90, in create 
remote:   module = import_module(entry) 
remote:   File 
"/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in 
import_module 
remote:   return _bootstrap._gcd_import(name[level:], package, 
level) 
remote:   File "<frozen importlib._bootstrap>", line 978, in 
_gcd_import 
remote:   File "<frozen importlib._bootstrap>", line 961, in 
_find_and_load 
remote:   File "<frozen importlib._bootstrap>", line 948, in 
_find_and_load_unlocked 
remote:  ModuleNotFoundError: No module named 'rest_framework' 
remote: 
remote: !  Error while running '$ python manage.py collectstatic -- 
noinput'. 
remote:  See traceback above for details. 
remote: 
remote:  You may need to update application code to resolve this 
error. 
remote:  Or, you can disable collectstatic for this application: 
remote: 
remote:   $ heroku config:set DISABLE_COLLECTSTATIC=1 
remote: 
remote:  https://devcenter.heroku.com/articles/django-assets 
remote: !  Push rejected, failed to compile Python app. 
remote: 
remote: !  Push failed 
remote: Verifying deploy... 
remote: 
remote: !  Push rejected to xplearner. 
remote: 
To https://git.heroku.com/xplearner.git 
! [remote rejected] master -> master (pre-receive hook declined) 
error: failed to push some refs to 'https://git.heroku.com/xplearner.git' 

爲「Heroku的」,但我沒有更多的運行應用程序在本地,因爲它不會在我的設置中找到restframework並在同一案件中,我得到這個錯誤,當我嘗試在線推出在Heroku項目:

ModuleNotFoundError at /admin/ 
No module named 'rest_framework' 

請某人建議這個問題的解決方案?我不正確的是什麼?

+1

它看起來像你忘了添加'rest_framework'到你的'requirements.txt'文件。你能向我們證明嗎? – Chris

+0

在PyPI中的BTW'rest_framework'被列爲'djangorestframework'。 – Felicio

+0

我沒加restframework我requirements.txt文件。我剛剛做到了,我也必須將遷移應用到我的heroku應用程序,並且工作正常。非常感謝,我很欣賞。 –

回答

0

也許這是一個python2/python3問題。您可以使用djangorestframework更改rest_framework如果您在本地使用此軟件包的python3,您是否可以提供關於需求和heroku confs的更多信息。

+0

感謝您的快速回復。問題出在我的requirements.txt文件上。我沒有添加restframework到它。謝謝,我感激。 –