python-如何在Heroku上启动已经制作好的Django应用
作者:互联网
我已经制作了一个在服务器上运行的django应用.我现在想使用heroku在网络上启动它,但是我发现的所有教程都使您开始了一个全新的项目.我不知道该怎么做才能将我现有的django项目更新为与heroku一起使用.
现在,我的文件的组织方式如下:
in hcp:
crunchWeb:
crunchWeb: files = _init_.py ; settings.py ; urls.py ; wsgi.py
crunchApp: files = _init_.py ; admin.py ; models.py ; views.py etc...
manage.py
sqlite3.db
env: folders= bin ; helloflask ; include ; lib #all of these were created automatically
templates: all my .html files
我想知道heroku教程(https://devcenter.heroku.com/articles/django#using-a-different-wsgi-server)中需要执行的命令以及可以跳过的命令.
我还想知道执行所有命令时需要放在哪个文件夹中
谢谢!
2012-09-06T21:44:52+00:00 app[web.1]: File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
2012-09-06T21:44:52+00:00 app[web.1]: File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/utils.py", line 92, in __getitem__
2012-09-06T21:44:52+00:00 app[web.1]: return getattr(connections[DEFAULT_DB_ALIAS], item)
2012-09-06T21:44:52+00:00 app[web.1]: backend = load_backend(db['ENGINE'])
2012-09-06T21:44:52+00:00 app[web.1]: File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/utils.py", line 24, in load_backend
2012-09-06T21:44:52+00:00 app[web.1]: return import_module('.base', backend_name)
2012-09-06T21:44:52+00:00 app[web.1]: File "/app/.heroku/venv/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
2012-09-06T21:44:52+00:00 app[web.1]: __import__(name)
2012-09-06T21:44:52+00:00 app[web.1]: File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 31, in <module>
2012-09-06T21:44:52+00:00 app[web.1]: raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)
2012-09-06T21:44:52+00:00 app[web.1]: django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3
2012-09-06T21:44:54+00:00 heroku[web.1]: Process exited with status 1
2012-09-06T21:44:54+00:00 heroku[web.1]: State changed from starting to crashed
2012-09-06T21:44:54+00:00 heroku[web.1]: State changed from crashed to starting
2012-09-06T21:44:58+00:00 heroku[web.1]: Starting process with command `python ./manage.py runserver 0.0.0.0:57395 --noreload`
2012-09-06T21:44:59+00:00 app[web.1]: File "./manage.py", line 10, in <module>
settings.py
# Django settings for crunchWeb project.
import dj_database_url
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}
# {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
# 'NAME': '/Users/Santi/hcp/crunchWeb/sqlite3.db', # Or path to database file if using sqlite3.
# 'USER': '', # Not used with sqlite3.
# 'PASSWORD': '', # Not used with sqlite3.
# 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
# 'PORT': '', # Set to empty string for default. Not used with sqlite3.
# }
# }
解决方法:
直接从方向https://devcenter.heroku.com/articles/django开始,再次阅读说明并按照说明进行操作,您将执行:
$pip install Django psycopg2 dj-database-url
数据库设置
接下来,配置应用程序以使用Heroku的Postgres数据库.安装的dj-database-url模块将自动从env执行所有操作.
将以下内容添加到您的settings.py中:
import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}
您可以在settings.py的末尾添加这些行,以继续在本地使用sql lite,并且仅在heroku上使用postgres.
settings.py
------------------------
import dj_database_url
import os
if os.getcwd() == "/app":
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}
标签:heroku,python,django 来源: https://codeday.me/bug/20191127/2076061.html