python - Simple django POST not working -


i have form this:

<form action="{% url "forum.posts" forum=forum.slug thread=thread.slug %}" method="post">     {% csrf_token %}     <div class="form-group">         <textarea class="form-control" placeholder="začni tipkati.."></textarea>     </div>     <input type="submit" class="btn btn-success" value="pošlji odgovor"> </form> 

views.py

''' display posts in thread or create new post in thread. ''' def posts(request, forum, thread):     forum = forum.objects.get(slug=forum)      thread = thread.objects.get(slug=thread)      if request.method == "post":          return httpresponse('ok')      posts = thread.posts.all()      return render(request, 'forum/posts.html', {         'forum': forum,         'thread': thread,         'posts': posts     }) 

urls.py (relevant part):

# list posts in thread / submit post forum url(r'^(?p<forum>[-\w]+)/(?p<thread>[-\w]+)/$', 'forum.views.posts', name='forum.posts'), 

html output:

<form action="/forum/o-spletiscu/novatemaa/" method="post">     <input type="hidden" name="csrfmiddlewaretoken" value="4pqwdsafhyjrhunyu5p9vvhtay3vlpbu">     <div class="form-group">         <textarea name="post-body" class="form-control" placeholder="začni tipkati.."></textarea>     </div>     <input type="submit" class="btn btn-success" value="pošlji odgovor"> </form> 

after hit submit, expect ok returned, instead page refreshes , nothing happens. normal requests working though..

what missing?

edit: it's working when use @csrf_exempt on posts method.

page refreshes , nothing happens

problem action value. try inspect , find wither url correct or not.

or

your form not have input name property.

try this:

  <form action="{% url "forum.posts" forum=forum.slug thread=thread.slug %}" method="post">       {% csrf_token %}       <div class="form-group">           <textarea class="form-control" placeholder="začni tipkati.." name="something"></textarea>       </div>       <input type="submit" class="btn btn-success" value="pošlji odgovor">   </form> 

Comments

Popular posts from this blog

python - Mongodb How to add addtional information when aggregating? -

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

java - Incorrect order of records in M-M relationship in hibernate -