Skip to content

Commit

Permalink
added error 404 handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Ardhanari committed Oct 17, 2019
1 parent dbdb241 commit bb84b5f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ def sorting_by_votes():
top_voted=mongo.db.repo.find().sort("votes", -1) # top voted first
return render_template("records.html", records=top_voted)

# handles 404 errors
@app.errorhandler(404)
def page_not_found(e):
return render_template('404.html'), 404

if __name__ == '__main__':
port = int(os.getenv('PORT', 5000))
Expand Down
21 changes: 21 additions & 0 deletions templates/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends 'base.html' %} {% block title %}404!{% endblock %}

{% block content %}

<div class="row">
<div class="input-field col s12">
<h4>Oh dear, this link isn't working!</h4>

<div class="row">
Go somewhere nice:
<p>
<ul>
<li><a href="{{ url_for('get_records')}}"><i class="material-icons left">home</i> Browse records</a></li><br>
<li><a href="{{ url_for('show_categories') }}"><i class="material-icons left">folder</i> Browse categories</a></li><br>
<li><a href="{{ url_for('add_record') }}"><i class="material-icons left">add</i> Add new link</a></li>
</ul>
</p>
</div>
</div>
</div>
{% endblock %}

0 comments on commit bb84b5f

Please sign in to comment.