Can you construct csrf from request object - csrf constructor exception?
<p>I am following an example of user registration and my code looks like this</p>

<pre><code>from django.views.decorators import  csrf
def register_user(request):
    args={}
    args.update(csrf(request)) #----&gt;Crashes here
    args["form"] = UserCreationForm()
    return render_to_response("register.html",args)
</code></pre>

<p>I get an exception at the statement </p>

<pre><code>args.update(csrf(request))
</code></pre>

<p>stating that the </p>

<pre><code>module object is not callable.
</code></pre>

<p>Any suggestions on what I might be doing wrong ?</p>

<p>Judging from your code, you need <code>django.template.context_processors.csrf()</code>, not <code>django.views.decorators.csrf</code>. This puts the csrf token in the template context.</p>

<p>The recommended way is to use <code>render</code> instead of <code>render_to_response</code>. This will run all configured <a href="https://docs.djangoproject.com/en/1.10/ref/templates/api/#using-requestcontext" rel="nofollow">context processors</a>, including the <code>csrf</code> context processor.</p>

<pre><code>from django.shortcuts import render

def register_user(request):
    args = {}
    args["form"] = UserCreationForm()
    return render(request, "register.html", args)
</code></pre>

<p>This is what allows you to use the <code>{% csrf_token %}</code> template tag in your templates.</p>

<p>You still need to use either the <code>CsrfViewMiddleware</code> (recommended) or <code>csrf_protect</code> decorator to actually protect your views. </p>

python django