Thanks Malcolm, What I'm looking after is sending my custom validation error message that is not covered by django.
Thank you very much On Apr 13, 10:15 am, Malcolm Tredinnick <[email protected]> wrote: > On Sun, 2009-04-12 at 23:37 +1000, Joshua Partogi wrote: > > Dear all, > > > I want to send and display validation error message from the view to > > the template, how do I do this in Django? I tried searching on the > > documents but could not find any topics on error message. Could anyone > > give me a hint on how to do this? > > Do you mean validation errors that are generated by a form when calling > is_valid()? If so, this happens automatically when the form is > redisplayed: > > def my_view(request, ...): > if request.method == "POST": > form = MyForm(request.POST) > if form.is_valid(): > ... > else: > # The "GET" path > form = MyForm() > ctxt = { > "form": form, > ... > } > return render_to_response("my_template.html", ctxt) > > In this sort of path, if an error occurs in the form, the form object > passed back to the template is the version with the data populated and > errors in place. So when the template displays the form, it will no > longer be an empty form (like it was the first time), but a form with > the initial submission filled in and error messages available. > > This is documented ([1]) but it's not necessarily the easiest thing to > find at the moment. > > [1]http://docs.djangoproject.com/en/dev/ref/forms/api/#how-errors-are-di... > > Is that what you were after? > > Regards, > Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

