Django Custom 500 Error Page
Contents |
layout of
Django 404 Template
all other site pages. This means avoiding that django 500 error log our users saw the dafault Apache error pages having the feeling that they
Django Return 500 Error
had quitted our application. Django offers a simple and elegant way to manage the more common HTTP errors, such as django raise 500 error 400, 403, 404 and 500, enabling us to specify our custom views and templates. All we need is to add these lines in our urls.py # urls.py from django.conf.urls import ( handler400, handler403, handler404, handler500 ) handler400 = 'my_app.views.bad_request' handler403 = custom 500 error page nginx 'my_app.views.permission_denied' handler404 = 'my_app.views.page_not_found' handler500 = 'my_app.views.server_error' # ... and implement our custom views in views.py. # views.py from django.shortcuts import ( render_to_response ) from django.template import RequestContext # HTTP Error 400 def bad_request(request): response = render_to_response( '400.html', context_instance=RequestContext(request) ) response.status_code = 400 return response # ... References Customizing error views ❤ 0 #django|#error pages|#http|#custom| Share Share this article on LinkedIn | Tweet this article | Share this article on Google+ View the discussion thread. blog comments powered by Disqus © 2011-2016 Elia Contini. The content of this website is licensed under a CC BY-NC-ND 4.0 International License. Elia Contini su LinkedIn Elia Contini su Twitter Elia Contini su Google+ Elia Contini su GitHub Elia Contini su Tumblr Elia Contini's Blog RSS
A view function, or view for short, is simply a Python function that takes a Web request and returns a
Custom 500 Error Page Example
Web response. This response can be the HTML contents of a custom 401 error page Web page, or a redirect, or a 404 error, or an XML document, or an image .
Custom 403 Error Page
. . or anything, really. The view itself contains whatever arbitrary logic is necessary to return that response. This code can live anywhere you want, as long http://blog.eliacontini.info/post/118617321553/django-custom-error-pages as it's on your Python path. There's no other requirement-no "magic," so to speak. For the sake of putting the code somewhere, the convention is to put views in a file called views.py, placed in your project or application directory. A simple view¶ Here's a view that returns the current date and time, https://docs.djangoproject.com/en/1.10/topics/http/views/ as an HTML document: from django.http import HttpResponse import datetime def current_datetime(request): now = datetime.datetime.now() html = "
It is now %s." % now return HttpResponse(html) Let's step through this code one line at a time: First, we import the class HttpResponse from the django.http module, along with Python's datetime library. Next, we define a function called current_datetime. This is the view function. Each view function takes an HttpRequest object as its first parameter, which is typically named request. Note that the name of the view function doesn't matter; it doesn't have to be named in a certain way in order for Django to recognize it. We're calling it current_datetime here, because that name clearly indicates what it does. The view returns an HttpResponse object that contains the generated response. Each view function is responsible for returning an HttpResponse object. (There are exceptions, but we'll get to those later.) Django's Time Zone DjangoGoogle. Het beschrijft hoe wij gegevens gebruiken en welke opties je hebt. Je moet https://www.youtube.com/watch?v=iulRRmatrGI dit vandaag nog doen. Navigatie overslaan NLInloggen Laden... Kies je taal. Sluiten Meer informatie View this message in English Je gebruikt YouTube in het Nederlands. Je kunt deze voorkeur hieronder wijzigen. Learn more You're viewing YouTube in Dutch. You can change this preference below. Sluiten Ja, nieuwe versie behouden Ongedaan maken Sluiten 500 error Deze video is niet beschikbaar. WeergavewachtrijWachtrijWeergavewachtrijWachtrij Alles verwijderenOntkoppelen Laden... Weergavewachtrij Wachtrij __count__/__total__ Creating a Blog with Django 1.7 - Video 6 : adding 404 and 500 eror pages Chris Hawkes AbonnerenGeabonneerdAfmelden34.98334K Laden... Laden... Bezig... Toevoegen aan Wil je hier later nog een keer naar kijken? Log in om deze video toe te voegen custom 500 error aan een afspeellijst. Inloggen Delen Meer Rapporteren Wil je een melding indienen over de video? Log in om ongepaste content te melden. Inloggen Transcript Statistieken 1.425 weergaven 8 Vind je dit een leuke video? Log in om je mening te geven. Inloggen 9 0 Vind je dit geen leuke video? Log in om je mening te geven. Inloggen 1 Laden... Laden... Transcript Het interactieve transcript kan niet worden geladen. Laden... Laden... Beoordelingen zijn beschikbaar wanneer de video is verhuurd. Deze functie is momenteel niet beschikbaar. Probeer het later opnieuw. Gepubliceerd op 11 jan. 2015CHECK OUT DEVMOUNTAIN (Coding Bootcamp)https://goo.gl/P4vgKS-~-~~-~~~-~~-~-This whole series can be found HERE https:--www.youtube.com-watch?v=F5i17gqeSrE&list=PLei96ZX_m9sV9Me7BVXL1RsiwZzUIrgrVThis tutorial covers the latest in Django using version 1.7. We are going to cover the beginning and end of making a full scale blogging website for production purposes. PLEASE SUBSCRIBE!! post any questions in the comments below. TAGSdjango 1.7, 1.7, 1-7, django, python, web, development, tutorial, easy, beginner, full, feat