python - Django - {% csrf_token %} was used in a template -
after submission, error 400 , following message:
create_foo.html:
<form class="modal-form" method="post" action="{% url 'create_foo'> %}"> {% csrf_token %} {{ forms }} </form>
create_foo.py:
@require_post @login_required(login_url='/login/') def create_foo(request): # # if form.is_valid(): return httpresponse('success', status=201) return jsonresponse({'html': render_to_string('create_foo.html', {'forms': form}), 'message': 'failed'}, status=400)
i have problem when error 400 have form message error.
i can not improve data on form , go on, , have error:
/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py:67: userwarning: {% csrf_token %} used in template, context did not provide value. caused not using requestcontext. "a {% csrf_token %} used in template, context "
the warning because not including request
when call render_to_string
. change to:
render_to_string('create_foo.html', {'forms': form}, request=request)
Comments
Post a Comment