New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect a settings module as Django project type #15

Closed
chrishas35 opened this Issue Dec 26, 2011 · 2 comments

Comments

Projects
None yet
2 participants
@chrishas35

chrishas35 commented Dec 26, 2011

I have a project with the following structure (following the recent advice of BDFL @jacobian, http://www.slideshare.net/jacobian/the-best-and-worst-of-django slide 51)

root/
    Procfile
    requirements.txt
    project/
        settings/
            __init__.py (empty)
            base.py
            sqlite.py
            postgres.py

Unfortunately, Heroku doesn't detect this as a Django project due to the fact that a settings.py file does not exist.

@kennethreitz

This comment has been minimized.

Contributor

kennethreitz commented Dec 26, 2011

Thanks for the feedback. This isn't the first time someone's asked us to support this. We'll keep it in mind.


Luckily, it is recognized as a regular Python application, and will work properly if you configure it. You'll just have to add a few lines to get the database info from the environment in your settings.

@chrishas35

This comment has been minimized.

chrishas35 commented Dec 26, 2011

Ahh, yes...I logged it and then decided to start hacking for a solution. Thanks for the tip and for including the relevant info in an environment variable.

For others who may come across this, the workaround is to add the following to the settings file being used:

# Manually inject Heroku settings due to lack of a settings.py file
# https://github.com/heroku/heroku-buildpack-python/blob/master/bin/compile
# 
# Issue logged https://github.com/heroku/heroku-buildpack-python/issues/15

import os
import sys
import urlparse
urlparse.uses_netloc.append('postgres')
urlparse.uses_netloc.append('mysql')

try:

    # Check to make sure DATABASES is set in settings.py file.
    # If not default to {}

    if 'DATABASES' not in locals():
        DATABASES = {}

    if 'DATABASE_URL' in os.environ:
        url = urlparse.urlparse(os.environ['DATABASE_URL'])

        # Ensure default database exists.
        DATABASES['default'] = DATABASES.get('default', {})

        # Update with environment configuration.
        DATABASES['default'].update({
            'NAME': url.path[1:],
            'USER': url.username,
            'PASSWORD': url.password,
            'HOST': url.hostname,
            'PORT': url.port,
        })
        if url.scheme == 'postgres':
            DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'

        if url.scheme == 'mysql':
            DATABASES['default']['ENGINE'] = 'django.db.backends.mysql'
except:
    print 'Unexpected error:', sys.exc_info()

podshumok pushed a commit to podshumok/heroku-buildpack-python that referenced this issue Dec 19, 2012

Merge pull request heroku#15 from timshadel/master
Add version to the sample package.json shown in README.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment