[Django]-Creating an app on Heroku with Django and NPM

19๐Ÿ‘

โœ…

Note: The multi buildpack is a much nicer way to accomplish this these days ๐Ÿ™‚


Iโ€™ve created a fork of the official Python heroku buildpack that allows an optional npm_requirements.txt for installing such dependencies.

I am now using coffeescript and less-css with django-compressor on heroku ๐Ÿ™‚

https://github.com/jiaaro/heroku-buildpack-django

Edit: To switch to my buildback from the standard buildpack:

  1. use the heroku command line app to set the BUILDPACK_URL environment variable:

    heroku config:add BUILDPACK_URL=git://github.com/jiaaro/heroku-buildpack-django.git 
    
๐Ÿ‘คJiaaro

34๐Ÿ‘

If you want to avoid maintaining a custom buildpack, you can use the multi buildpack.

Using the multi buildpack is super simple:

  1. Run heroku config:add BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git
  2. Create a .buildpacks file in the root of your repository with two lines:
    https://github.com/heroku/heroku-buildpack-nodejs.git
    https://github.com/heroku/heroku-buildpack-python.git
  3. Create a package.json file with your npm dependencies.
  4. Run npm install
๐Ÿ‘คyndolok

3๐Ÿ‘

You can create your own buildpack, that mix nodejs buildbpack and python buildpack. Or compile your CoffeeScript on your machine and put it on S3.

๐Ÿ‘คcyberdelia

3๐Ÿ‘

I found this question in Google while solving the same problem for myself.
I merged two official buildpacks (python and nodejs), so now one can have Django project with standard npm-description file package.json by running this command:

heroku config:add BUILDPACK_URL=https://github.com/podshumok/heroku-buildpack-python

This solution differs from Jiaaroโ€™s one in the following:

  • it is based on the newer (dec 12) versions of buildpacks (for example, it runs collectstatic on deployment)
  • you need correct package.json file (at least name and version of your product should be specified in this file)
  • npm dependencies should be listed in package.json
๐Ÿ‘คpodshumok

3๐Ÿ‘

@Jiaaro โ€˜s solution didnโ€™t work for meโ€ฆ Causes some weird errorโ€ฆ /:

File "almalinks/manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management

Was too tired to deal with it, so I looked around and I found this nifty resource:
โ€“ The heroku-django cookbook

They explain how you can add your own scripts that hook into herokuโ€™s default buildpacks.
Worked like a charm. ๐Ÿ™‚

๐Ÿ‘คAlex Zak

1๐Ÿ‘

Things have changed in Heroku land

There is no need for multi build packs, .builpack files, or custom build packs. Simply add the required official heroku build packs to your heroku app and they will execute in the order entered. Use the index option to reorder them as required.

heroku buildpacks:add --index 1 heroku/nodejs -a your_app_name

There is also no need for, gunt tasks, apps like django-bower, or other specialized tools that take up server resources and slow build time.

You can check out my tutorial on how to seamlessly integrate Django + Bower + Heroku here.

๐Ÿ‘คArctelix

Leave a comment