Add robots and custom 404/500 pages
parent
83e97884ea
commit
e8e5bf34a3
|
@ -6,6 +6,7 @@ urlpatterns = patterns(
|
|||
'network.base.views',
|
||||
url(r'^$', 'index', name='home'),
|
||||
url(r'^about/$', TemplateView.as_view(template_name='base/about.html'), name='about'),
|
||||
url(r'^robots\.txt$', 'robots', name='robots'),
|
||||
|
||||
# Observations
|
||||
url(r'^observations/$', 'observations_list', name='observations_list'),
|
||||
|
|
|
@ -7,7 +7,7 @@ from django.views.decorators.http import require_POST
|
|||
from django.shortcuts import get_object_or_404, render, redirect
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.timezone import now, make_aware, utc
|
||||
from django.http import JsonResponse
|
||||
from django.http import JsonResponse, HttpResponseNotFound, HttpResponseServerError, HttpResponse
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
from network.base.models import (Station, Transponder, Observation,
|
||||
|
@ -34,6 +34,23 @@ def index(request):
|
|||
return render(request, 'base/home.html', ctx)
|
||||
|
||||
|
||||
def custom_404(request):
|
||||
"""Custom 404 error handler."""
|
||||
return HttpResponseNotFound(render(request, '404.html'))
|
||||
|
||||
|
||||
def custom_500(request):
|
||||
"""Custom 500 error handler."""
|
||||
return HttpResponseServerError(render(request, '500.html'))
|
||||
|
||||
|
||||
def robots(request):
|
||||
data = render(request, 'robots.txt', {'environment': settings.ENVIRONMENT})
|
||||
response = HttpResponse(data,
|
||||
content_type='text/plain; charset=utf-8')
|
||||
return response
|
||||
|
||||
|
||||
def observations_list(request):
|
||||
"""View to render Observations page."""
|
||||
observations = Observation.objects.all()
|
||||
|
|
|
@ -59,6 +59,8 @@ body {
|
|||
font-family:'ClearSans';
|
||||
}
|
||||
|
||||
|
||||
|
||||
a:hover {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
@ -93,6 +95,13 @@ a:hover {
|
|||
border-color: #eed3d7;
|
||||
}
|
||||
|
||||
.error {
|
||||
margin-top: 40px;
|
||||
width: 500px;
|
||||
margin: auto;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.img-avatar {
|
||||
border: 2px solid white;
|
||||
border-radius: 50px;
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 6.8 KiB |
|
@ -1,9 +1,20 @@
|
|||
{% extends "base.html" %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block title %}Page Not found{% endblock %}
|
||||
{% block title %} - Page Not found{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Page Not found</h1>
|
||||
<div class="error">
|
||||
<h1>404</h1>
|
||||
|
||||
<p>This is not the page you were looking for.</p>
|
||||
{% endblock content %}
|
||||
<h3>Page Not Found</h3>
|
||||
|
||||
<p>
|
||||
This is not the page you were looking for.
|
||||
Head back to <a href="{% url 'base:home' %}">homepage</a>.
|
||||
</p>
|
||||
|
||||
<p><img src="{% static 'img/error.png' %}"></p>
|
||||
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
|
|
@ -1,12 +1,20 @@
|
|||
{% extends "base.html" %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block title %}Server Error{% endblock %}
|
||||
{% block title %} - Server Error{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Ooops!!! 500</h1>
|
||||
<div class="error">
|
||||
<h1>500</h1>
|
||||
|
||||
<h3>Looks like something went wrong!</h3>
|
||||
<h3>Server Error</h3>
|
||||
|
||||
<p>We track these errors automatically, but if the problem persists feel free to contact us. In the meantime, try refreshing.</p>
|
||||
<p>
|
||||
We track these errors automatically, but if the problem persists feel free to contact us.
|
||||
In the meantime, try refreshing. Head back to <a href="{% url 'base:home' %}">homepage</a>.
|
||||
</p>
|
||||
|
||||
<p><img src="{% static 'img/error.png' %}"></p>
|
||||
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
user-agent: *
|
||||
{% if environment == 'dev' %}
|
||||
Disallow: /admin/
|
||||
{% else %}
|
||||
Disallow: /
|
||||
{% endif %}
|
|
@ -1,12 +1,12 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.conf.urls import patterns, include, url
|
||||
from django.conf.urls.static import static
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
|
||||
handler404 = 'network.base.views.custom_404'
|
||||
handler500 = 'network.base.views.custom_500'
|
||||
|
||||
urlpatterns = patterns(
|
||||
'',
|
||||
|
||||
|
@ -21,4 +21,11 @@ urlpatterns = patterns(
|
|||
url(r'^api/', include('network.api.urls'))
|
||||
)
|
||||
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
if settings.DEBUG:
|
||||
urlpatterns += patterns(
|
||||
'',
|
||||
url(r'^404/$', handler404),
|
||||
url(r'^500/$', handler500),
|
||||
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
|
||||
{'document_root': settings.MEDIA_ROOT}),
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue