Issues deploying django-nvd3 charts on heroku - django

Did any one try to deploy django-nvd3 charts on to Heroku recently with success? I was trying to deploy django application using nvd3 charts on to heroku the whole weekend with no luck. It works perfectly fine in my dev enviornment (ubuntu). However when I try to push it to Heroku, am facing all sorts of errors.
on Dev environment I installed npm (this includes node.js) and later installed bower and finally installed django-bower; as suggested on https://github.com/areski/django-nvd3. I tried different charts and all work okay, with no issues
However, when I was trying to push the code over to Heroku, I was hitting quite a few errors. Fixing one leads to others. I was wondering, if I need to add a package.json (to list npm dependencies like bower) and bower.json (to list bower dependencies like d3, nvd3) files to my repo, in the first place?
I googled a lot for some documentation that gives gun-shot info on this(django, nvd3, bower, npm/node all married together), but couldn't see any
Note: I will try to post heroku logs for more info.
bower.json is given something like:
{
"dependencies": {
"d3": "3.3.6",
"nvd3": "1.1.12-beta"
}
package.json is given something like:
"engines": {
"node": "0.11.11",
"npm": "1.3.25"
},
"dependencies": {
"bower": "1.3.1"
}
Errors I encountered are something like:
1. gunicorn is not recognized - resolved this
2. NameError: Name 'DATABASES' is not defined in settings.py - resolved this
3. django.core.management is not found - resolved this
4. Git error: fatal: HEAD corrupted/ cannot be deployed on to heroku - resolved this
5. listening at localhost 127.0.0.1:8000 - am working on this. I think this is also to do with my DATABASES setting that is pointing at dj_database_url.config(default=['DATABASE_URL'])??
Is there any Git repo with django+nvd3charts that is deployed successfully on to Heroku? Can I have a look at the configuration?
Also looking at https://github.com/areski/django-nvd3; I do not see any bower dependencies or npm dependencies listed here, does it work like this?
Or, can Heroku automatically install npm/bower without package.json and also can it look at settings.py file and by looking at bower dependencies, does Heroku also install those dependencies with out a need for bower.json file to specifically listing d3, nvd3 as dependencies? I suppose its not the case, as far as I could see
Please suggest

I wrote a blog post about this which you find here: https://mattdoesstuff.wordpress.com/2015/04/10/getting-npm-d3-nvd3-django-bower-django-bower-nvd3-and-heroku-to-play-nicely-together/
Use django-nvd3 and django-bower
pip install django-nvd3 django-bower
pip freeze > requirements.txt
git add .
git commit -m "don't forget your requirements.txt!"
Use a multi-buildpack
heroku config:set BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git
Use the Node and Python buildpacks together
# ./.buildpacks
https://github.com/heroku/heroku-buildpack-nodejs.git
https://github.com/amanjain/heroku-buildpack-python-with-django-bower.git
Download bower using npm
# ./package.json
{"private": true,"dependencies": {"bower": "1.4.1"}}
User django-bower to collect its assets
# ./bin/post_compile
# install bower components
./manage.py bower_install
Tell django where to find bower
# settings.py
...
import os
APPLICATION_DIR = os.path.dirname(globals()['__file__'])
HEROKU = bool(os.environ.get('DATABASE_URL'))
BOWER_COMPONENTS_ROOT = os.path.join(APPLICATION_DIR, 'components')
# where to find your local bower
BOWER_PATH = '/usr/local/bin/bower'
if HEROKU:
BOWER_PATH = '/app/node_modules/bower/bin/bower'
BOWER_INSTALLED_APPS = (
'd3#3.3.13',
'nvd3#1.7.1',
)
...
Credits
* http://www.rawsrc.com/using-django-bower-on-heroku/
* https://github.com/ddollar/heroku-buildpack-multi.git
* https://github.com/areski/django-nvd3

Related

Error during deploying django app in Heroku

I am trying to deploy a Django application to Heroku. When I followed the documentation and tried the command git push heroku master, I am getting an error: failed to push some refs to 'https://git.heroku.com/sleepy-eyrie-25993.git'. I searched online and tried to use git pull. But it didn't work. I also tried using git push -f heroku master, but still getting the same error. Is there any other way to do it? I followed this doc
https://devcenter.heroku.com/articles/python-support.
Tried using the heroku dashboard, but it is giving the same error
Building on the Heroku-18 stack ! No default language could be detected for this app. HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically. See https://devcenter.heroku.com/articles/buildpacks ! Push failed
You can also deploy from your application dashboard on Heroku
Heroku deployment requires requirements.txt in the root of the repository.
Also, to run a Django app - it requires file Procfile
Sample content:
web: gunicorn your_app_name.wsgi:application --log-file -
You can also try to specify buildpack manually by executing:
heroku buildpacks:set heroku/python
Then if there are additional errors starting - they will be more specific
Also settings.py of your Django application should contain the following:
import django_heroku
django_heroku.settings(locals())
For more details, please refer Here

using browser-sync with django on docker-compose

I'm doing a project for college and I've never used docker before, I usually use browser-sync when working on static files, but now when I'm using Django on docker-compose (i followed THIS tutorial ), I have no idea how to set it up to work, can anybody give me advice or direct me?
So, i found a solution,
Start by following the tutorial here to set up django with docker-compose, by the end of this you should have a working base django project. then follow the steps below.
How to Use "livereload" With "docker-compose" :
on you host machine, open the command line or the terminal and do :
pip install --upgrade pip
pip install django-livereload-server
pip install psycopg2-binary
PS: i'm using psycopg2 in docker-compose that's why i'm installing it,
if you're using something else, install it instead of psycopg2
Now add to the requirements.txt file (from the tutorial) this line
django-livereload-server
The file should look like this (if you followed the tutorial step by step, you can change according to what db you want to use)
Django==2.0
psycopg2-binary
django-livereload-server
Open the terminal, cd to your projects directory, and do:
docker-compose build
to download the new django-livereload to your docker environment.
Now, you've everything installed,
you need to setup your project to use the django-livereload-server module,
In your project's settings.py
add livereload to INSTALLED_APPS:
INSTALLED_APPS = [
...
'livereload',
...
]
and add the livereload middleware to MIDDLEWARE:
MIDDLEWARE = [
...
'livereload.middleware.LiveReloadScript',
]
and make sure that DEBUG is set to True.
now you can start developing,
open 2 consoles (terminals) in your project's directory
in the first one do :
python manage.py livereload
wait until the server starts, when it's working, leave it running, and in the second terminal do:
docker-compose up
the server in the second terminal is running the django development server, and the server in the first terminal is feeding the first one a livereload.js file, which is used by the django-livereload-server module to inject css, automatically reload html and js when saving, .. etc
PS : make sure the first server (livereload) is working before you launch the second one
i hope this helped !

heroku PostGIS syncdb error

I am having trouble getting a simple GeoDjango app running on heroku. I have created the postgis extension for my database but I am not able to run syncdb without getting the following error:
from django.contrib.gis.geometry.backend import Geometry
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/gis/geometry/backend/__init__.py", line 14, in <module>
'"%s".' % geom_backend)
django.core.exceptions.ImproperlyConfigured: Could not import user-defined GEOMETRY_BACKEND "geos".
Any ideas what I am doing wrong? Also does anyone know of a tutorial for getting a simple geodjango project running on heroku? Thanks for your help
I ran into this same issue and Joe is correct, you are missing a buildpack. What I did differently was include both the heroku-geo-buildpack and the heroku-buildpack-python. Both can be included by using the heroku-buildpack-multi and adding a ".buildpacks" file to your home directory in which to include the other buildpacks.
https://github.com/ddollar/heroku-buildpack-multi
So set buildpack-multi as your buildpack and add a .buildpacks file in your project base directory:
$ heroku config:set BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git
$ touch .buildpacks
# .buildpacks
https://github.com/cyberdelia/heroku-geo-buildpack.git#1.0
https://github.com/heroku/heroku-buildpack-python
When you push this, Heroku will install the software packages required to run python (python, pip, etc), along with the software packages required to run postgis (geos, proj and gdal).
I gave heroku-buildpack-geodjango a try but I believe it might be out of date (hasn't been updated in a year).
I just ran into the exact same error after using the multi buildpack method from ddollar https://github.com/ddollar/heroku-buildpack-multi with no problems up until this morning. As Jeff writes, you just point your buildpack at the multi and then add a .buildpacks file.
$ heroku config:set BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git
$ cat .buildpacks
# .buildpacks
https://github.com/cyberdelia/heroku-geo-buildpack.git
https://github.com/heroku/heroku-buildpack-python
Also dont forget to add django.contrib.gis to the apps in settings.
Everything should go well and install the geos and gdal libs when you push to heroku but you will find that django doesnt find them and you get the error. This is because django wants the full path as per the docs:
https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/geolibs/
So add this to settings.py:
GEOS_LIBRARY_PATH = "{}/libgeos_c.so".format(environ.get('GEOS_LIBRARY_PATH'))
GDAL_LIBRARY_PATH = "{}/libgdal.so".format(environ.get('GDAL_LIBRARY_PATH'))
It seems like you are missing some C libraries. Consider the GeoDjango Heroku buildpack:
https://github.com/cirlabs/heroku-buildpack-geodjango/
heroku create --stack cedar --buildpack http://github.com/cirlabs/heroku-buildpack-geodjango/
git push heroku master
The required libraries should be installed automatically using these commands.

Installing a gem bundle in a python app on Heroku

I have a Python app on Heroku running with Django. The app launches and works perfectly. The first couple lines of a push look like this:
(venv)➜ djangoproject git:(development) ✗ git push
Counting objects: 33, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (21/21), done.
Writing objects: 100% (21/21), 1.96 KiB, done.
Total 21 (delta 15), reused 0 (delta 0)
-----> Heroku receiving push
-----> Python/Django app detected
...
I need to install a gem program on the dyno (specifically, Compass).
Heroku's instructions are to provide a Gemfile and Gemfile.lock in the root directory with the required gems. As soon as I provide this, however, Heroku thinks the app is a Ruby app:
(venv)➜ djangoproject git:(development) ✗ git push
Counting objects: 33, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (21/21), done.
Writing objects: 100% (21/21), 1.96 KiB, done.
Total 21 (delta 15), reused 0 (delta 0)
-----> Heroku receiving push
-----> Ruby app detected (NOTE: this is paraphrased)
...
Is there any way I can install a ruby gem while running the site as a Python/Django app?
Try explicitly selecting the python buildpack by using heroku config:add BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-python.git
It will still perform the detection process but I think (?) it will run the buildpack you've explicitly selected before or instead of attempting any others, and since you still have a python application installed, it should work.
Note that after you do the config:add you need to rebuild your slug on Heroku, which currently can ONLY be done by pushing an actual code change via git. You can make an empty git commit if you don't have any real changes to push, using git commit --allow-empty -m "Empty commit"
You can also create a new project using the --buildpack command line option.
I ran into the same problem and this worked for me:
https://github.com/ddollar/heroku-buildpack-multi
How it works:
You explicitly tell Heroku that you want to use this "multi" buildpack using the "heroku config:add BUILDPACK_URL=..." command
You create a .buildpacks file in your root directory that simply lists the git URLs for the various buildpacks you want to use. I used the python and ruby buildpacks.
git push to Heroku and watch all buildpacks get used
It's also worth mentioning that the python buildpack has a couple of hooks that you can use to do additional custom work. If you create a bin/pre_compile file or a bin/post_compile file then those scripts will be called by the python buildpack just before/after the main compile step. So you could also use these hooks to get Ruby or other dependencies installed. But IMO it's easier to let Ruby's own buildpack install the Ruby dependencies.
You need to use custom buildpack that allows you to build both ruby and python dependencies.
heroku config:add BUILDPACK_URL=https://github.com/mandest/heroku-buildpack-rubypython
Add a Gemfile to your project Run bundle install locally (to create
Gemfile.lock file) Push your Gemfile and Gemfile.lock to heroku
That should first install ruby, then run bundle install, then install python, and all deps in the requirements.txt file.
Howeve, in my case, I also wanted to run some commands using ruby libraries, namebly SASS/COMPASS. In order to do that, you have two options I think. First one, is to fork above repository and add running those commands in the build (this way they have all needed privileges rather than you running heroku run ...).
The second options is to add a Rakefile and specify those things in rake assets:precompile task.
So, in my case with Compass the Rakefile looks like:
require 'yaml'
require 'pathname'
require 'rspec/core/rake_task'
include FileUtils
namespace 'assets' do
desc 'Updates the stylesheets generated by Sass/Compass'
task :precompile do
print %x(compass compile --time)
end
end

How can i install external pinax projects?

I try to deal with poor documentation of Pinax.
I found this project
https://github.com/pinax/pinax-multiblog-project
what i want is that install it. I normally install a project called account but here i have to install from git . How can i do that in Pinax
Edit:
It turns out the new way of using projects is to just copy the folder and rename it.
Usage instructions:
So to use the multiblog project you would do
Copy the multiblog inside the cloned repo to a new location and rename it to the name you would like to use for your project. Then install the requirements via pip and follow the rest of the steps for setting up a django project
OSX/Linux:
cd ~/src
git clone https://github.com/pinax/pinax-multiblog-project
cp -r ~/src/pinax-project-admin ~/Sites/new_project
cd ~/Sites/new_project"
pip install -r requirements.txt
python manage.py syncdb
I too have been trying to accomplish the same thing. So far I found this commit
https://github.com/nrb/pinax/blob/476d2398c48cc444eb2338c12090f0cebad46961/docs/starterprojects.txt
Relevant section on begins on line 160 near the end
External Starter Projects
=========================
The Pinax ``setup_project`` command can also use starter projects built by third parties.
These can either be plain directory structures, or they may be a git/hg pip editable.
To install a starter project from an external source, simply pass the file path or git/hg
URL to the ``-b`` option::
pinax-admin setup_project -b git+git://github.com/user/project.git#egg=project my_new_project
However all the pinax projects I have come across don't seem to include an egg to use
eg:
https://github.com/pinax/pinax-multiblog-project
https://github.com/pinax/pinax-project-account
I need to use Django 1.4 for my project but the included account base project in both Pinax 0.9a2 and 0.9b1-dev10 use Django 1.3.
I am guessing the external project integration is something we will have to wait for in the Pinax 1.0 release.