Search code examples
djangoherokuvirtualenvcedar

Deploying multiple projects on Heroku with Django


I would like to deploy two separate Django applications to Heroku. Two applications, with two separate domain names, that are logically different from each other. I set up a venv that contain all the Python/Django stuff. Now, I could create another application that duplicates all the Python/Django stuff in another project. But, is there a way to use the same venv?

My file structure currently looks like this

django
-.git
-projectname_1
-venv
.gitignore
requirements.txt

When I tried to add projectname_2 under django I got an error saying Django app must be in a package subdirectory

Is there a correct way to add a second application using the same venv?


Solution

  • This error occurs when your project doesn't conform to Heroku's specs for a Django project.

    Specifically, that particular error occurs when Heroku did not find a settings file at ~/your_app_name/settings.py and therefore assumed it's a non-Django Python app. But then it did find settings.py and manage.py at your project root (~/).

    The specific Heroku source code that throws this error is: https://github.com/heroku/heroku-buildpack-python/blob/master/bin/compile

    Your directory should look something like this:

    ~/.gitignore
    ~/Procfile
    ~/requirements.txt
    ~/your_app_name/
    ~/your_app_name/manage.py
    ~/your_app_name/settings.py
    ~/your_app_name/etc...
    

    Your best bet really is to use two separate Heroku apps. Heroku makes some assumptions about what type of app you are deploying and doesn't necessarily account for multiple apps.

    Also, it's probably best to not check in your virtualenv. Just make sure all your dependencies are defined in requirements.txt and Heroku will install them automatically inside a new virtualenv.