Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You don't have to manually pass <code>user</code> when rendering the template. Try doing this.</p> <p>In <strong>view.py</strong>:</p> <pre><code>from django.contrib.auth.decorators import login_required from django.shortcuts import render @login_required def profile(request): return render(request, 'profile.html') </code></pre> <p>In <strong>settings.py</strong></p> <pre><code>LOGIN_URL = '/accounts/login/' </code></pre> <p>In <strong>index.html</strong>:</p> <pre><code>{% if user.is_authenticated %} &lt;li&gt;&lt;a href="/accounts/profile/"&gt;Profile&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="/accounts/logout/"&gt;logout&lt;/a&gt;&lt;/li&gt; {% else %} &lt;li&gt;&lt;a href="/accounts/login/"&gt;login&lt;/a&gt;&lt;/li&gt; {% endif %} </code></pre> <p>In <strong>profile.html</strong></p> <pre><code>{% extends "index.html" %} {% block application %} {% if user.is_authenticated %} &lt;p&gt;Welcome, {{ user.username }}. Thanks for logging in.&lt;/p&gt; {% else %} &lt;p&gt;Welcome, new user. Please log in.&lt;/p&gt; {% endif %} {% endblock %} </code></pre> <p><strong>In page1 view:</strong></p> <pre><code>from django.shortcuts import render from django.contrib.auth.decorators import login_required # If you want only authenticated users to access this page @login_required def car(request): all_cars = Car.objects.all().filter(active=1).values('id', 'name') return render(request, 'page1.html', {'all_cars': all_cars}) </code></pre> <blockquote> <p>PS: I strongly suggest you to use named urls and use url names instead of hardcoding urls.</p> </blockquote>
    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.
 

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