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 8235523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:50:25+00:00 2026-06-07T18:50:25+00:00

I have a page in my Django app that needs to do one of

  • 0

I have a page in my Django app that needs to do one of the following depending on the status of the logged in user in relation to a group (not a Django user group; something custom to my app) represented on the page:

  1. If the user can join the group, display a link to join the group.
  2. If the user is in the group, display a link to leave the group.
  3. If the user can’t join the group, don’t display either link.

One way of doing this would be to create three templates (one with the join link, one with the leave link, and one with no link) and choose the appropriate one in the view. I feel like it may be overkill to have three different templates that will only differ in one line of code, so I have not gone that route as of yet.

Displaying the correct content for conditions 1 and 2 exclusively using a template is not possible, and if it were I do not think it would be advisable. Users to groups is a many-to-many relationship, and determining group membership requires passing a user to the group or passing a group to the user.

Since Django templates don’t allow passing function arguments, I am trying to solve this by passing a context variable to the template using get_context_data.

def get_context_data(self, **kwargs):
    context = super(NetworkDetails, self).get_context_data(**kwargs)
    user = ???
    context['in_group'] = user.in_group(context['group_detail'])
    return context

If I do that, how can I get the currently logged in user within that method? If that isn’t possible, where else can I get that information outside of the template? Is there an accepted method of doing something like this?

Thanks!

  • 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-07T18:50:28+00:00Added an answer on June 7, 2026 at 6:50 pm

    One way of doing this would be to create three templates (one with the
    join link, one with the leave link, and one with no link) and choose
    the appropriate one in the view

    That’s funny because if you can choose what template to include, you can just choose what html to display. Instead of:

    {% if join_link %}
        {% include 'join_link.html' %}
    {% endif %}
    {% if leave_link %}
        {% include 'leave_link.html' %}
    {% endif %}
    {% if not join_link and not leave_link %}
        you can't join
    {% endif %}
    

    You could just have:

    {% if join_link %}
        <a href="{{ join_link }}">join</a>
    {% endif %}
    {% if leave_link %}
        <a href="{{ leave_link }}">leave</a>
    {% endif %}
    {% if not join_link and not leave_link %}
        you can't join
    {% endif %}
    

    So, I don’t understand why you want to use template inclusion.

    If I do that, how can I get the currently logged in user within that method?

    self.request.user
    self.request.user.is_authenticated() # return True if the user is logged in
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a client that has an app built with django. On every page
I have a form in my Django app (not in admin) that allows staff
I have a Django app that needs to pull the follower_count information from several
I have a web application written in Django that has one specific page I'd
I have written a django page that requires only super users to login. So
I have a simple django page that has a counter on it. I use
I have a django app that has / at the end of every URL
I have a signup form that needs to be loaded for every page of
I have a Django app that uses Haystack . Is it possible to show
I have created a django app. It has got a user login/registration on the

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.