title: Show message with Ajax in modal window
body: <p>I have little problem in my Django project. My project has modal window where users create new object. There is only one field (name) in that modal window. Also I use AJAX. I am tring to check if the same object is already exist and show message in that modal. You can see code which I tried to use but unfortunatly I dont see any messages. How can I make message in Ajax?</p>
  
  <p><strong>views.py</strong>:</p>
  
  <pre><code>def function_add(request, project_code):
      data = dict()
      project = get_object_or_404(Project, pk=project_code)
      if request.method == 'POST':
          form = FunctionAddForm(request.POST)
          if form.is_valid():
              name = form.cleaned_data['name']
              if Function.objects.filter(name=name, project=project_code).exists():
                  messages.warning(request, 'Already exist.')
              else:
                  function = form.save(commit=False)
                  function.project = project
                  function.save()
              data['form_is_valid'] = True
              functions = Function.objects.filter(project=project_code)
              data['html_function'] = render_to_string('project/function_list.html', {'functions': functions})
          else:
              data['form_is_valid'] = False
      else:
          form = FunctionAddForm()
      context = {'project': project, 'form': form}
      data['html_function_add_form'] = render_to_string('project/function_add.html', context, request=request)
      return JsonResponse(data)
  </code></pre>
  
  <p><strong>function_add.html</strong>:</p>
  
  <pre><code>{% if messages %}
      &lt;ul class="messages"&gt;
           {% for message in messages %}
                &lt;li class="{{ message.tags }}"&gt;{{ message }}&lt;/li&gt;
           {% endfor %}
      &lt;/ul&gt;
  {% endif %}
  </code></pre>