Thursday, September 17, 2015

Error handling

The worst feeling in the world is seeing that ugly default page whenever you stumble across an error in your Django app. Make lemonade out of those lemons by customizing your error pages like so:

Add this to urls.py:
handler404 = 'eat_decisive.views.handler404'
handler500 = 'eat_decisive.views.handler500'

Add this to views.py:
def handler404(request):
    return render(request, '404.html')

def handler500(request):
    return render(request, '500.html')

---

Create your html files (place in top level of your templates folder)
404.html
       

{% extends 'eat_decisive/base.html' %}

{% load staticfiles %}

{% block title %}Page not found {% endblock title %}

{% block body_block %}
<h1> YOUR ERROR HEADLINE HERE. </h1>

<p> YOUR ERROR MESSAGE HERE. </p>
{% endblock body_block %}


Now create a similar file for 500.html.

I added a Jane Austen quote to my 404 page, just for kicks. And because I love the phrase "intolerably stupid." Gotta remember to use that more often.


Committing code to both Heroku and Github

I found it a bit confusing that Heroku uses git, but whenever I entered git push heroku master, I wasn't updating my github repository...I was only updating the Heroku git location.

To make sure you update both locations correctly, from your master branch, enter

git remote -v
in the command line to see what other branches you currently have set up.

If you are in the midst of working on a Heroku deployment, but have also committed code to a Github repository in the past, you will get a list of both Heroku & Github links when you enter the command above (differentiated clearly in parentheses after each link).

This is useful if you want to double check that you have the correct Github repository set as "origin" before doing committing code by typing:
git push origin master

Hooray!