Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango - How to show messages under ajax function
    text
    copied!<p>I am using AjaxForm plugin to submit my form without refresh. like:</p> <pre><code>$('#my_form_id').ajaxForm(function(){ //something on success or fail }); </code></pre> <p>this works correctly. when i click submit button it saves form datas without refresh. But before this ; i had django messages on my template file like:</p> <pre><code>{% for message in messages %} &lt;div id="notice" align="center"&gt; {{ message }} &lt;/div&gt; {% endfor %} </code></pre> <p>what this code does is displaying notifications if post saved correctly or something failed.</p> <p>now; i can't do that. i dont understand how i can use these messages tags with ajax functions.</p> <p>it just saves the post. no notifications.</p> <p>thank you.</p> <p>edit : </p> <p>add_post url : <code>url(r'^admin/post/add/$', view='add_post',name='add_post'),</code></p> <p>related view : </p> <pre><code>@login_required(login_url='/login/') def add_post(request): template_name = 'add.html' owner = request.user if request.method == "POST": form = addForm(request.POST) if form.is_valid(): titleform = form.cleaned_data['title'] bodyform = form.cleaned_data['body'] checkform = form.cleaned_data['isdraft'] n = Post(title=titleform, body=bodyform, isdraft=checkform, owner=owner) n.save() messages.add_message(request, messages.SUCCESS, 'New post created successfully!') else: messages.add_message(request, messages.WARNING, 'Please fill in all fields!') else: form = addForm() return render_to_response(template_name, {'form': form, 'owner': owner,}, context_instance=RequestContext(request)) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload