├── .env ├── .gitignore ├── Procfile ├── Procfile.windows ├── README.md ├── app.json ├── gettingstarted ├── __init__.py ├── settings.py ├── static │ └── humans.txt ├── urls.py └── wsgi.py ├── hello ├── __init__.py ├── admin.py ├── migrations │ ├── 0001_initial.py │ └── __init__.py ├── models.py ├── static │ ├── js │ │ └── src │ │ │ ├── hello.js │ │ │ ├── test1.js │ │ │ ├── test2.js │ │ │ └── world.js │ └── lang-logo.png ├── templates │ ├── base.html │ ├── db.html │ └── index.html ├── tests.py └── views.py ├── index.html ├── manage.py ├── package.json ├── requirements.txt ├── runtime.txt └── webpack.config.js /.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=postgres:///python_getting_started 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | venv 2 | *.pyc 3 | staticfiles 4 | .env 5 | db.sqlite3 6 | .idea 7 | .DS_Store 8 | dist/ 9 | node_modules 10 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: gunicorn gettingstarted.wsgi --log-file - 2 | -------------------------------------------------------------------------------- /Procfile.windows: -------------------------------------------------------------------------------- 1 | web: python manage.py runserver 0.0.0.0:5000 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # django-webpack-heroku-example 2 | 3 | A barebones Python app using Webpack and React, which can easily be deployed to Heroku. 4 | 5 | This application supports the [Getting Started with Python on Heroku](https://devcenter.heroku.com/articles/getting-started-with-python) article - check it out. 6 | 7 | ## Running Locally 8 | 9 | Make sure you have Node and NPM [installed property](https://nodejs.org) 10 | 11 | Make sure you have Python [installed properly](http://install.python-guide.org). Also, install the [Heroku Toolbelt](https://toolbelt.heroku.com/) and [Postgres](https://devcenter.heroku.com/articles/heroku-postgresql#local-setup). 12 | 13 | ```sh 14 | $ npm install 15 | $ npm run webpack 16 | $ pip install -r requirements.txt 17 | $ createdb python_getting_started 18 | $ heroku local:run python manage.py migrate 19 | $ python manage.py collectstatic 20 | $ heroku local 21 | ``` 22 | 23 | Your app should now be running on [localhost:5000](http://localhost:5000/). 24 | 25 | ## Add Buildpacks 26 | 27 | ```sh 28 | $ heroku buildpacks:add --index 1 heroku/nodejs 29 | $ heroku buildpacks:add --index 2 heroku/python 30 | ``` 31 | 32 | 33 | ## Deploying to Heroku 34 | 35 | ```sh 36 | $ heroku create 37 | $ git push heroku master 38 | $ heroku run python manage.py migrate 39 | $ heroku open 40 | ``` 41 | or 42 | 43 | [](https://heroku.com/deploy) 44 | 45 | ## Documentation 46 | 47 | For more information about using Python on Heroku, see these Dev Center articles: 48 | 49 | - [Python on Heroku](https://devcenter.heroku.com/categories/python) 50 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Python on Heroku example", 3 | "description": "A barebones Python app, which can easily be deployed to Heroku.", 4 | "logo": "https://photos-1.dropbox.com/t/2/AABCmL8w0GvyYBEjfGa49LRXCNIVv7jQ2yg_0J5qnv93HQ/12/1636974/png/32x32/1/1446253200/0/2/heroku-logo-stroke-purple.png/EN6UqwEYpKq3MyAHKAc/j4JHowjJ5xrFapcyO-1V_jJ_lR_4spjZEfBvaPPArTs?size_mode=2&size=1280x960", 5 | "image": "heroku/python", 6 | "repository": "https://github.com/heroku/python-getting-started", 7 | "keywords": ["python", "django" ], 8 | "addons": [ "heroku-postgresql" ] 9 | } -------------------------------------------------------------------------------- /gettingstarted/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamSamskies/django-webpack-heroku-example/bb736e42f84423125d7797bb053be3be9d1babe5/gettingstarted/__init__.py -------------------------------------------------------------------------------- /gettingstarted/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for gettingstarted project, on Heroku. Fore more info, see: 3 | https://github.com/heroku/heroku-django-template 4 | 5 | For more information on this file, see 6 | https://docs.djangoproject.com/en/1.8/topics/settings/ 7 | 8 | For the full list of settings and their values, see 9 | https://docs.djangoproject.com/en/1.8/ref/settings/ 10 | """ 11 | 12 | import os 13 | import dj_database_url 14 | 15 | 16 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 17 | BASE_DIR = os.path.dirname(os.path.dirname(__file__)) 18 | PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) 19 | 20 | 21 | # Quick-start development settings - unsuitable for production 22 | # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ 23 | 24 | # SECURITY WARNING: change this before deploying to production! 25 | SECRET_KEY = 'i+acxn5(akgsn!sr4^qgf(^m&*@+g1@u^t@=8s@axc41ml*f=s' 26 | 27 | # SECURITY WARNING: don't run with debug turned on in production! 28 | DEBUG = True 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = ( 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 'hello' 41 | ) 42 | 43 | MIDDLEWARE_CLASSES = ( 44 | 'django.contrib.sessions.middleware.SessionMiddleware', 45 | 'django.middleware.common.CommonMiddleware', 46 | 'django.middleware.csrf.CsrfViewMiddleware', 47 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 48 | 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 49 | 'django.contrib.messages.middleware.MessageMiddleware', 50 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51 | 'django.middleware.security.SecurityMiddleware', 52 | ) 53 | 54 | ROOT_URLCONF = 'gettingstarted.urls' 55 | 56 | TEMPLATES = [ 57 | { 58 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 59 | 'DIRS': [], 60 | 'APP_DIRS': True, 61 | 'OPTIONS': { 62 | 'debug': True, 63 | 'context_processors': [ 64 | 'django.template.context_processors.debug', 65 | 'django.template.context_processors.request', 66 | 'django.contrib.auth.context_processors.auth', 67 | 'django.contrib.messages.context_processors.messages', 68 | ], 69 | }, 70 | }, 71 | ] 72 | 73 | WSGI_APPLICATION = 'gettingstarted.wsgi.application' 74 | 75 | 76 | # Database 77 | # https://docs.djangoproject.com/en/1.9/ref/settings/#databases 78 | 79 | DATABASES = { 80 | 'default': { 81 | 'ENGINE': 'django.db.backends.sqlite3', 82 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 83 | } 84 | } 85 | 86 | # Password validation 87 | # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators 88 | 89 | AUTH_PASSWORD_VALIDATORS = [ 90 | { 91 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 92 | }, 93 | { 94 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 95 | }, 96 | { 97 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 98 | }, 99 | { 100 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 101 | }, 102 | ] 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/1.8/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'en-us' 108 | TIME_ZONE = 'UTC' 109 | USE_I18N = True 110 | USE_L10N = True 111 | USE_TZ = True 112 | 113 | 114 | # Update database configuration with $DATABASE_URL. 115 | db_from_env = dj_database_url.config(conn_max_age=500) 116 | DATABASES['default'].update(db_from_env) 117 | 118 | # Honor the 'X-Forwarded-Proto' header for request.is_secure() 119 | SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') 120 | 121 | # Allow all host headers 122 | ALLOWED_HOSTS = ['*'] 123 | 124 | # Static files (CSS, JavaScript, Images) 125 | # https://docs.djangoproject.com/en/1.8/howto/static-files/ 126 | 127 | STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles') 128 | STATIC_URL = '/static/' 129 | 130 | # Extra places for collectstatic to find static files. 131 | STATICFILES_DIRS = ( 132 | os.path.join(PROJECT_ROOT, 'static'), 133 | ) 134 | 135 | # Simplified static file serving. 136 | # https://warehouse.python.org/project/whitenoise/ 137 | STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage' 138 | 139 | -------------------------------------------------------------------------------- /gettingstarted/static/humans.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamSamskies/django-webpack-heroku-example/bb736e42f84423125d7797bb053be3be9d1babe5/gettingstarted/static/humans.txt -------------------------------------------------------------------------------- /gettingstarted/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls import include, url 2 | 3 | from django.contrib import admin 4 | admin.autodiscover() 5 | 6 | import hello.views 7 | 8 | # Examples: 9 | # url(r'^$', 'gettingstarted.views.home', name='home'), 10 | # url(r'^blog/', include('blog.urls')), 11 | 12 | urlpatterns = [ 13 | url(r'^$', hello.views.index, name='index'), 14 | url(r'^db', hello.views.db, name='db'), 15 | url(r'^admin/', include(admin.site.urls)), 16 | ] 17 | -------------------------------------------------------------------------------- /gettingstarted/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for gettingstarted project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gettingstarted.settings") 12 | 13 | from django.core.wsgi import get_wsgi_application 14 | from whitenoise.django import DjangoWhiteNoise 15 | 16 | application = get_wsgi_application() 17 | application = DjangoWhiteNoise(application) -------------------------------------------------------------------------------- /hello/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamSamskies/django-webpack-heroku-example/bb736e42f84423125d7797bb053be3be9d1babe5/hello/__init__.py -------------------------------------------------------------------------------- /hello/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /hello/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by Django 1.9.1 on 2016-01-27 21:54 3 | from __future__ import unicode_literals 4 | 5 | from django.db import migrations, models 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | initial = True 11 | 12 | dependencies = [ 13 | ] 14 | 15 | operations = [ 16 | migrations.CreateModel( 17 | name='Greeting', 18 | fields=[ 19 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 20 | ('when', models.DateTimeField(auto_now_add=True, verbose_name=b'date created')), 21 | ], 22 | ), 23 | ] 24 | -------------------------------------------------------------------------------- /hello/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamSamskies/django-webpack-heroku-example/bb736e42f84423125d7797bb053be3be9d1babe5/hello/migrations/__init__.py -------------------------------------------------------------------------------- /hello/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | class Greeting(models.Model): 5 | when = models.DateTimeField('date created', auto_now_add=True) 6 | -------------------------------------------------------------------------------- /hello/static/js/src/hello.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export default function Hello() { 4 | return ( 5 |
This is a sample Python application deployed to Heroku. It's a reasonably simple app - but a good foundation for understanding how to get the most out of the Heroku platform.
14 | Getting Started with Python 15 | Source on GitHub 16 |