Reputation: 2102
I have already made a django app that runs on my server. I now want to launch it on the web using heroku but all the tutorials that I find make you start a whole new project. I dont know what to do to simply update my already existing django project to work with heroku.
My files now are organized like so:
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
I would like to know what commands from the heroku tutorial (https://devcenter.heroku.com/articles/django#using-a-different-wsgi-server) I still need to do and which ones I can skip.
I would also like to know in what folder I need to be in when executing all of my commands
Thanks!
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', '[email protected]'),
)
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.
# }
# }
Upvotes: 3
Views: 4960
Reputation: 2173
DIRECTLY FROM THE DIRECTIONS https://devcenter.heroku.com/articles/django, once again if you read the directions and follow them you will have executed:
$pip install Django psycopg2 dj-database-url
Next, configure the application to use Heroku’s Postgres database. The installed dj-database-url module will do everything automatically from the env.
Add the following to your settings.py:
import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}
You can add these lines at the end of your settings.py to continue to use sql lite locally and only postgres on heroku.
settings.py
------------------------
import dj_database_url
import os
if os.getcwd() == "/app":
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}
Upvotes: 3
Reputation: 3831
The heroku/django deployment tutorial you have linked is still your best bet. I just deployed an existing app following through that tutorial, and skipping steps I had already done, such as:
virtualenv venv --distribute
django-admin.py startapp...
manage.py syncdb...
git init
Basically if you have already done this for your existing app DRY!
I don't see a requirements.txt in your folder structure above so make sure you
pip freeze > requirements.txt
To make this less likely to ruin my existing code I did the following
# create a branch for testing heroku
git checkout -b heroku_test
#... follow the heroku tutorial
# add my changes
git add .
git commit -m "Heroku deployment steps"
# add the heroku remote
git remote add heroku [address]
git push heroku heroku_test:master
The last part of the push statement heroku_test:master
lets you push your local branch heroku_test
to your remote branch master
. (Otherwise heroku will just ignore the commit as it is not on the master branch).
Upvotes: 0