Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango - Using context_processor
    primarykey
    data
    text
    <p>I want to put a login form everywhere in my webpage so I added a <code>context_processor</code> and I included it in base.html file. The problem now is I cannot see the form.</p> <p>Here is my context_processors.py:</p> <pre><code>def global_login_form(request): if request.method == 'POST': formLogin = LoginForm(data=request.POST) if formLogin.is_valid(): from django.contrib.auth import login login(request, formLogin.get_user()) ... else: formLogin = LoginForm() return {'formLogin': formLogin} </code></pre> <p>And here are the diferents htmls I tried in base.html trying to invoke the form:</p> <pre><code>&lt;form action="/myapp/login/" method="post"&gt; {% csrf_token %} {{global_login_form}} &lt;/form&gt; &lt;form action="/myapp/login/" method="post"&gt; {% csrf_token %} {{global_login_form.as_p}} &lt;/form&gt; &lt;form action="/myapp/login/" method="post"&gt; {% csrf_token %} {{request.formLogin}} &lt;/form&gt; </code></pre> <p>first time I load the page, the <code>context_process</code> returns <code>{'formLogin': formLogin}</code> (cause <code>formLogin</code> is <code>LoginForm()</code>) but I cannot see the form while inspecting the html. It is not there... but I can see the <code>csrf_token</code> so I think I'm not invoking the context properly.</p> <p>Just it case (maybe the order is incorrect), here is settings.py:</p> <pre><code>TEMPLATE_CONTEXT_PROCESSORS = ( "myapp.context_processors.global_login_form", "django.core.context_processors.request", "django.contrib.auth.context_processors.auth", ) </code></pre> <p>Any ideas?</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.
 

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