Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8755675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:54:03+00:00 2026-06-13T13:54:03+00:00

I have one problem with users menu. So, I want, that authenticated user can

  • 0

I have one problem with users menu. So, I want, that authenticated user can see his/her profile page and logout (links) in menu. It works (when I logging in) on index page: index, page1, profile, logout ,but, if I go to the, for example, page1 I can see in menu: index, page1, login, not profile and logout. How to fix it?

in urls:

url(r'^accounts/login/$', 'django.contrib.auth.views.login' ),
url(r'^accounts/logout/$', 'django.contrib.auth.views.logout_then_login' ),
url(r'^accounts/profile/$', 'my_app.views.profile' ),

in views:

def profile(request):
    if  not request.user.is_authenticated():
        return HttpResponseRedirect("/accounts/login/")        
    else:
        user = request.user.is_authenticated()
        return  render_to_response('profile.html',locals()) 

Part of index.html:

{% if user.is_authenticated or request.user.is_authenticated %}
    <li><a href="/accounts/profile/">Profile</a></li>
    <li><a href="/accounts/logout/">logout</a></li>
{% else %}
    <li><a href="/accounts/login/">login</a></li>
{% endif %}

login.html:

{% extends "index.html" %}
{% load url from future %}

{% block application %}

{% if form.errors %}
<p>Try one more time</p>
{% endif %}

<form method="post" action="{% url 'django.contrib.auth.views.login' %}">
{% csrf_token %}
<table>
<tr>
    <td>{{ form.username.label_tag }}</td>
    <td>{{ form.username }}</td>
</tr>
<tr>
    <td>{{ form.password.label_tag }}</td>
    <td>{{ form.password }}</td>
</tr>
</table>

<input type="submit" value="Login" />
<input type="hidden" name="next" value="{{ next }}" />
</form>

{% endblock %}

profile.html:

{% extends "index.html" %}
{% block application %}
{% if request.user.is_authenticated %}
    <p>Welcome, {{ request.user.username }}. Thanks for logging in.</p>
{% else %}
    <p>Welcome, new user. Please log in.</p>
{% endif %}
{% endblock %}

page1.html:

{% extends "index.html" %}
{% block application %}
some for loops here
{% endblock %}

views for page1:

def car(request):
    all_cars = Car.objects.all().filter(active=1).values('id', 'name')
    return render_to_response('page1.html', {'all_cars': all_cars})
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:54:04+00:00Added an answer on June 13, 2026 at 1:54 pm

    You don’t have to manually pass user when rendering the template. Try doing this.

    In view.py:

    from django.contrib.auth.decorators import login_required
    from django.shortcuts import render
    
    @login_required
    def profile(request):
        return render(request, 'profile.html')
    

    In settings.py

    LOGIN_URL = '/accounts/login/'
    

    In index.html:

    {% if user.is_authenticated %}
        <li><a href="/accounts/profile/">Profile</a></li>
        <li><a href="/accounts/logout/">logout</a></li>
    {% else %}
        <li><a href="/accounts/login/">login</a></li>
    {% endif %}
    

    In profile.html

    {% extends "index.html" %}
    {% block application %}
    {% if user.is_authenticated %}
        <p>Welcome, {{ user.username }}. Thanks for logging in.</p>
    {% else %}
        <p>Welcome, new user. Please log in.</p>
    {% endif %}
    {% endblock %}
    

    In page1 view:

    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})
    

    PS: I strongly suggest you to use named urls and use url names instead
    of hardcoding urls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a menu item that I want to show/hide only if the user
I have a menu that asks for the user to pick one of the
The problem: I have set of pictures, when the user presses on one of
I have one problem with Javascript Nodes.I want to find out what button was
I have one problem , I want to get some data from XML file
I have a custom control in my mater page that represents a menu, let's
I'm writing a user account page where users can change their settings, and the
I have an html menu, when one item from it gets clicked I want
I have a website which is one page and the user navigates to each
I have one problem with parsing *.docx document with OpenXML (C#). So, here's my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.