Guilherme Noronha
Guilherme Noronha

Reputation: 630

Custom error pages using django 1.10

Hello I'm newbie in Django,

I'm looking to creating custom error pages to my app and found this site: http://blog.eliacontini.info/post/118617321553/django-custom-error-pages

However the 'render_to_response' is not used in Django 1.10

How do I transcript this code to Django 1.10

With best regards.

Upvotes: 1

Views: 277

Answers (2)

Kaushal Dontula
Kaushal Dontula

Reputation: 279

Django 1.10 passes three parameters to the page_not_found (https://docs.djangoproject.com/en/1.10/ref/views/#django.views.defaults.page_not_found)

create a function in your custom exceptions view

from django.shortcuts import render
def page_not_found(request, exception,  template_name='404.html'):
    return render(request, "page-not-found.html", context=None, status=404)

then add this line to your urls.py

handler404 = 'path_to_exceptions_view.page_not_found'

Upvotes: 0

Hybrid
Hybrid

Reputation: 7049

render_to_response() still works in Django 1.10, but if you want to use the more classical approach, you can use render(). Example:

from django.shortcuts import render

def myview(request):
    if request.METHOD == 'GET':
        context = {}
        return render(request, 'index.html', context, status=404)

Upvotes: 1

Related Questions