I would like to know how to show a personalized error with get_object_or_404?, I do not want regular http404 pages, I want to display a message with the result none
get_object_or_404
thank:)
get_object_or_404()- Essentially simple 5 line function. If you have no specific reason for using it, simply do:
get_object_or_404()
try: instance = YourModel.objects.get(pk=something) except YourModel.DoesNotExist: return render_to_response('a_template_with_your_error_message.html')
If for any reason you have to use get_object_or_404 (), you can try putting it in a block try: ... except Http404: ..., but I honestly can't come up with a plausible reason for this.
try: ... except Http404: ...
, get_object_or_404 , http 404. , DEBUG, : "No MyModel ".
doc. : Model, * args ** kwargs. get() filter() .
. , , django.shortcuts [1].
, ?get_object_or_404() 404 ?, , django 404 html .
. Http404. - try catch, . ,
try catch
try: obj = Model.objects.get(pk = foo) except: return HttpResponseRedirect('/no/foo/for/you') #or return render_to_response ...