Disappearing {% csrf_token %} on website file
<p>When I wanted use my registration form in my site, I get ERROR 403: "CSRF verification failed. Request aborted." In source of this website I realised that  is missing. This is part of view-source from my site:</p>

<pre><code>&lt;div style="margin-left:35%;margin-right:35%;"&gt;
&lt;fieldset&gt;
&lt;legend&gt; Wszystkie pola oprÃ³cz numeru telefonu naleÅ¼y wypeÅniÄ &lt;/legend&gt;
    &lt;form method="post" action="."&gt;
        &lt;p&gt;&lt;label for="id_username"&gt;Login:&lt;/label&gt; &lt;input id="id_username" maxlength="30" name="username" type="text" required/&gt;&lt;/p&gt;
&lt;p&gt;&lt;label for="id_email"&gt;Email:&lt;/label&gt; &lt;input id="id_email" name="email" type="email" required /&gt;&lt;/p&gt;
&lt;p&gt;&lt;label for="id_password1"&gt;HasÅo:&lt;/label&gt; &lt;input id="id_password1" name="password1" type="password" required /&gt;&lt;/p&gt;
&lt;p&gt;&lt;label for="id_password2"&gt;PowtÃ³rz hasÅo:&lt;/label&gt; &lt;input id="id_password2" name="password2" type="password" required /&gt;&lt;/p&gt;
&lt;p&gt;&lt;label for="id_phone"&gt;Telefon:&lt;/label&gt; &lt;input id="id_phone" maxlength="20" name="phone" type="text" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;label for="id_log_on"&gt;Logowanie po rejestracji:&lt;/label&gt;&lt;input id="id_log_on" name="log_on" type="checkbox" /&gt;&lt;/p&gt;
        &lt;input type="submit" value="Rejestracja"&gt;&lt;input type="reset" value="WartoÅci poczÄtkowe"&gt;
    &lt;/form&gt;
&lt;/fieldset&gt;
&lt;/div&gt;
</code></pre>

<p>I was surprised of that, because in my files on Pythonanythere this fragment of code is present.</p>

<p>This is part of my file register.html on Pythonanythere:</p>

<pre><code>&lt;div style="margin-left:35%;margin-right:35%;"&gt;
&lt;fieldset&gt;
&lt;legend&gt; Wszystkie pola oprÃ³cz numeru telefonu naleÅ¼y wypeÅniÄ &lt;/legend&gt;
    &lt;form method="post" action="."&gt;{% csrf_token %}
        {{ form.as_p }}
        &lt;input type="submit" value="Rejestracja"&gt;&lt;input type="reset" value="WartoÅci poczÄtkowe"&gt;
    &lt;/form&gt;
&lt;/fieldset&gt;
&lt;/div&gt;
</code></pre>

<p>What am I doing wrong that my webpage don't see this piece of code? It is seamed on server but on webpage view-source It isn't.</p>

<p>EDIT:
This is view, which render my template:</p>

<pre><code>def register(request):
    if request.method == 'POST':
    form = FormularzRejestracji(request.POST)
    if form.is_valid():
        user = User.objects.create_user(
            username=form.cleaned_data['username'],
            password=form.cleaned_data['password1'],
            email=form.cleaned_data['email']
        )
        user.last_name = form.cleaned_data['phone']
        user.save()
        if form.cleaned_data['log_on']:
            user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password1'])
            login(request, user)
            template = get_template("osnowa_app/point_list.html")
            variables = RequestContext(request, {'user': user})
            output = template.render(variables)
            return HttpResponseRedirect("/")
        else:
            template = get_template("osnowa_app/register_success.html")
            variables = RequestContext(request, {'username': form.cleaned_data['username']})
            output = template.render(variables)
            return HttpResponse(output)

else:
    form = FormularzRejestracji()
template = get_template("osnowa_app/register.html")
form = FormularzRejestracji()
variables = RequestContext(request, {'form': form})
output = template.render(variables)
return HttpResponse(output)
</code></pre>

<p>You should pass a plain dict and the request object to <code>template.render()</code>, not a <code>RequestContext</code>. The template engine will convert it to a <code>RequestContext</code> for you:</p>

<pre><code>template = get_template("osnowa_app/register.html")
context = {'form': form}
output = template.render(context, request)
</code></pre>

<p>Right now, the <code>template.render()</code> function sees a dict-like object as the first argument, but no request as the second argument. Without a request as the second argument, it converts the dict-like <code>RequestContext</code> into a plain <code>Context</code> object. Since the <code>Context</code> object doesn't run context processors, your context is missing the csrf token. </p>

<p>Alternatively you can just use the <a href="https://docs.djangoproject.com/en/1.10/topics/http/shortcuts/#render" rel="nofollow"><code>render</code> shortcut</a>, which returns a <code>HttpResponse</code> object with the rendered template as content:</p>

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

def register(request):
    ...
    return render(request, "osnowa_app/register.html", {'form': form})
</code></pre>

<p>This particular case is also being discussed in <a href="https://code.djangoproject.com/ticket/27258" rel="nofollow">ticket #27258</a>. </p>

python html django django-templates pythonanywhere