Continuing from the last time, a memo for making a python application on heroku This time, I will focus on the errors that were caught in the development.
Reference source: https://gist.github.com/konitter/5370904 http://voluntas.hatenablog.com/entry/20110919/1316426034 http://qiita.com/nakazye/items/48651e39f07da82fe79e
The main body of heroku is
$ sudo gem install heroku
You can install it with, but an error occurs immediately ...
Operation not permitted - /usr/bin/…/
It seems that the installation folder does not have permission, it is solved by changing the installation folder
$ sudo gem install -n /usr/local/bin heroku
(Reference source: http://qiita.com/AcaiBowl/items/4bb4708de03e6ee14a4a)
virtualenv
Create a folder for development
$ mkdir heroku-django
$ cd heroku-django
In the created folder, expand virtualenv. It is recommended to develop with virtualenv on heroku! !! (To minimize the required libraries)
$ virtualenv --no-site-packages .
$ source bin/activate
$ pip install django
$ env ARCHFLAGS="-arch i386 -arch x86_64" bin/pip install psycopg2
$ pip install gunicorn
Record the installed libraries in requirements.txt in the heroku_django directory
$ pip freeze > requirements.txt
Create a Procfile on heroku_django directory (required to use gunicorn on heroku) I stumbled because it didn't move easily
Procfile
web: gunicorn --pythonpath './mysite' mysite.wsgi --log-file -
It's okay with one line. The point is to specify the python path
From here, it is the same as normal djnago development http://eiry.bitbucket.org/ It is summarized in an easy-to-understand manner.
Create a .gitignore file in the heroku_django directory (Because you don't push unnecessary files)
.gitignore
bin/
include/
lib/
*.pyc
When deploying
$ git push heroku master
Error occurred
Error while running '$ python mysite/manage.py collectstatic --noinput'.
Error that static folder cannot be created on heroku, solved by adding the following 3 lines to setting.py
#### **`setting.py`**
```python
PROJECT_DIR = os.path.dirname(__file__)
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
Command to create a static folder just below the directory folder
Before deploying
$ python manage.py runserver
Or
$ foreman start
Let's check if the app works with.
bootstrap Precautions when using bootstrap Error that is displayed well on runserver but cannot read css well on foreman start http://stackoverflow.com/questions/16170030/django-serves-static-files-with-runserver-but-not-with-foreman Is pinpoint.
$ pip install whitenoise
Is necessary.
Recommended Posts