title: How to show custom error in Django?
body: <p>I am new to Django, and here is what I have do so far.</p>
  
  <p>I wanted to take in CharField data and validate it as URL. I have done the following.</p>
  
  <p>models.py</p>
  
  <pre><code>from django.db import models
  
  class Small(models.Model):
      url_new = models.CharField(max_length=500, default='abc', unique=True)
  
  def __str__(self):
          return self.url_new
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>from django.shortcuts import render, HttpResponseRedirect, Http404
  from django.core.validators import URLValidator
  from django.core.exceptions import ValidationError
  
  from .forms import SmallForm, URLForm
  from .models import Small
  def home(request):
      form = SmallForm(request.POST or None)
      if form.is_valid():
          url_validate = URLValidator()
          url_new = form.cleaned_data['url_new']
  
          try:
              url_validate(url_new)
          except ValidationError:
              raise form.fields['url_new'].error_messages['Invalid URL']
  
      context = {"form": form}
          template = "home.html"
          return render(request, template, context)
  </code></pre>
  
  <p>forms.py</p>
  
  <pre><code>from django import forms
  
  from .models import Small
  
  
  class URLForm(forms.Form):
      url_new = forms.CharField()
  
  
  class SmallForm(forms.ModelForm):
      class Meta:
          model = Small
          fields = ["url_new", ]
  </code></pre>
  
  <p>so, I am able to validate the form on html page, but only when the form is empty and i click on submit button.</p>
  
  <p>but when i click on submit after entering a non-url content in the form field it takes me to a new page and shows the <code>error_messages</code> which is <code>Invalid URL</code> (when debug is true).</p>
  
  <p>Is there any way I can validate it and show the error message on the html page rather than showing me a debug page?</p>
  
  <p>Thanks in advance.</p>