Skip to content
This repository has been archived by the owner on May 20, 2021. It is now read-only.

Commit

Permalink
update to include custom css
Browse files Browse the repository at this point in the history
  • Loading branch information
CaseyFaist committed Apr 30, 2019
1 parent 1a73e0b commit 1560db8
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ dynowiki/static/mptt/
dynowiki/static/wiki/
dynowiki/static/staticfiles.json
media/
static/
dynowiki/static/
107 changes: 107 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# From Project to Productionized on Heroku

Hello!

Originally created for PyCon 2019 Heroku Workshop, this project demonstrates the
principles of 12 Factor Architecture and how to achieve that in your application
for deploying to production. Heroku is our deployment server, but the principles
demonstrated are applicable to any deployment schema and are a best practice for
building robust, quick-recover applications in the cloud.

This project utilizes [Django-Wiki](https://github.com/django-wiki/django-wiki), but this project ideally models what any locally built and working project can update to become productionized.

With that in mind, here are the specific changes needed to get a locally running
app with minimal adjustments from the original `startapp` configuration deployed!

>note: To clone and run this project locally from scratch, check out the related
guide [LOCALSETUP](LOCALSETUP.md)

## Step 1: Create a .gitignore

This will enable you to smoothly run your application locally and
in production with minimal headache.

In addition to whatever you'd normally place in your .gitignore, be sure to
[untrack](https://git-scm.com/docs/git-rm#Documentation/git-rm.txt---cached) the following files:
```
/your-venv-directory
__pycache__
db.sqlite3 # not needed if you're using Postgres locally
yourapp/static/admin/
yourapp/static/mptt/ # these are generated by django-wiki but it's better
yourapp/static/wiki/ # they be generated on deploy
yourapp/static/staticfiles.json
media/
static/
```

>note: Don't add your migrations to .gitignore! We're not covering any app
migrations here, but your migrations should live in your source control - see
the [Django docs](https://docs.djangoproject.com/en/2.2/topics/migrations/#the-commands) for more details.

Commit this and untrack files as necessary, and you're good to go.

## Step 2: Modularize your settings

### 2.a - Settings folder

This step is pretty straight forward, but can lead to errors if you forget to
update all the references.

In the same directory that your `settings.py` file is located, create a new
directory called `settings/`. Place your `settings.py` file into that new dir
and rename it - I chose `local.py`, but you can use `dev.py` or whatever makes
sense to you.

### 2.b

Now navigate to your `manage.py`. Somewhere around the 6th line, you'll see the
main process setting the default `DJANGO_SETTINGS_MODULE` to
`yourproject.settings`. Update that to `yourproject.settings.local`, or whatever
you named your local settings file.

### 2.c

Navigate to `wsgi.py`, located in `yourproject/`. You'll see a similar line here
setting the default `DJANGO_SETTINGS_MODULE`; change it the same way here.

## 3 Changes to local.py

For twelve factor deployment and deployment on Heroku, a few changes are needed
in your `local.py` file.

### Whitenoise

[Whitenoise](http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-with-django) is a package for managing static assets, installed via pip. It's in
our `requirements.txt` file, so it'll automatically get installed when we deploy
but we still have to install it as middleware.

Scroll to the `MIDDLEWARE` list and place the following line at index 1, or 2nd
in the list:

`'whitenoise.middleware.WhiteNoiseMiddleware',`

The order that middleware is loaded is important, which is why we need to add
this change to our local.py file. More on that in a bit.

For local-prod parity, let's enable WhiteNoise's [caching and compression](http://whitenoise.evans.io/en/stable/django.html#add-compression-and-caching-support) locally
by adding the following line to the bottom of your `local.py`:

`STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'`

## Step 4: heroku.py

We're splitting out our local and production settings, and now it's time to add
a file specifying our production settings. I named this file `heroku.py` since
that's where I'll be deploying, but `prod.py` works just as well.



These are needed in your prod (Heroku) file:

pip install environ, gunicorn, psycopg2

copy paste:


heroku run python manage.py createsuperuser
8 changes: 8 additions & 0 deletions wikistuff/static/dynowiki/css/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.navbar-inverse {
background-color: #3a2778;
border-bottom-color: transparent;
}

a:active {
background-color: transparent
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1560db8

Please sign in to comment.