Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango CSRF error on form submission
    primarykey
    data
    text
    <p>I am writing a Django app. Here is my code:</p> <p><strong>edit.module.html</strong> (template; removing extra html markup):</p> <pre><code>&lt;h1&gt;Enter the HTML below&lt;/h1&gt; &lt;form action="./update/" method="post"&gt; {% csrf_token %} &lt;textarea cols='55' rows='15'&gt;&lt;/textarea&gt; &lt;input type='submit' value='Submit' /&gt; &lt;/form&gt; </code></pre> <p><strong>urls.py</strong></p> <pre><code>url(r'^myapp/update/$', 'myproj.myapp.views.update_module'), </code></pre> <p><strong>view.py</strong></p> <pre><code>from django.http import HttpResponse from django.shortcuts import render_to_response, get_object_or_404 from django.core.context_processors import csrf from django.template import RequestContext #Select the module you want to edit def edit_modules(request): lpconf = {"module_to_edit" : "top"} return render_to_response('admin/edit.module.html', lpconf, context_instance=RequestContext(request)) def update_module(request): return render_to_response('admin/updated.html', context_instance=RequestContext(request)) </code></pre> <p>When I submit the form I get CSRF error: "CSRF verification failed. Request aborted."</p> <p>I followed the Django documentation (<a href="https://docs.djangoproject.com/en/dev/ref/contrib/csrf/" rel="nofollow">https://docs.djangoproject.com/en/dev/ref/contrib/csrf/</a>) and tried to fix the problem but I couldn't. What am I doing wrong here?</p> <p>Thanks.</p> <p>UPDATE: Updated view.py functions edit_modules and update_modules. edit_modules is the one rendering the form and update_modules is the one processing it. Now, I am not getting CSRF error. I am now getting the error: <strong>Empty module name</strong></p> <p>UPDATE: I was able to fix it. I was using one view to render the form and another one to process it. I had to add context to the first view that was rendering the form.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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