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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:56:55+00:00 2026-05-28T15:56:55+00:00

Django newbie at work and I could use some pointers. I’m using django-profile and

  • 0

Django newbie at work and I could use some pointers. I’m using django-profile and have been working on my profile page which is handled by the views.profile_detail. The problem I am facing is I am unable to put another variable in my template by using this view. Here is my view function:

def profile_detail(request, username, public_profile_field=None,
               template_name='profiles/profile_detail.html',
               extra_context=None):
"""
Detail view of a user's profile.

If no profile model has been specified in the
``AUTH_PROFILE_MODULE`` setting,
``django.contrib.auth.models.SiteProfileNotAvailable`` will be
raised.

If the user has not yet created a profile, ``Http404`` will be
raised.

**Required arguments:**

``username``
    The username of the user whose profile is being displayed.

**Optional arguments:**

``extra_context``
    A dictionary of variables to add to the template context. Any
    callable object in this dictionary will be called to produce
    the end result which appears in the context.

``public_profile_field``
    The name of a ``BooleanField`` on the profile model; if the
    value of that field on the user's profile is ``False``, the
    ``profile`` variable in the template will be ``None``. Use
    this feature to allow users to mark their profiles as not
    being publicly viewable.

    If this argument is not specified, it will be assumed that all
    users' profiles are publicly viewable.

``template_name``
    The name of the template to use for displaying the profile. If
    not specified, this will default to
    :template:`profiles/profile_detail.html`.

**Context:**

``profile``
    The user's profile, or ``None`` if the user's profile is not
    publicly viewable (see the description of
    ``public_profile_field`` above).

**Template:**

``template_name`` keyword argument or
:template:`profiles/profile_detail.html`.

"""
user = get_object_or_404(User, username=username)
# accuracy = ''
try:
    profile_obj = user.get_profile()
    accuracy = str(profile_obj.number_of_answers / profile_obj.number_of_answers) + '%'
except ObjectDoesNotExist:
    raise Http404
if public_profile_field is not None and \
   not getattr(profile_obj, public_profile_field):
    profile_obj = None

if extra_context is None:
    # extra_context = {'accuracy': potato}
    extra_context = {}
context = RequestContext(request)
# context['accuracy'] = 'potato'
for key, value in extra_context.items():
    context[key] = callable(value) and value() or value

return render_to_response(template_name,
                          {'profile': profile_obj},
                          # { 'profile': profile_obj, 'accuracy': accuracy},
                          # locals(),
                          context_instance=context)

and here is my template:

{% extends "base.html" %}
{% load i18n %}

{% block content %}
<p><strong>Level:</strong><br>{{ profile.level }}</p>
<p><strong>Bounty Points:</strong><br>{{ profile.total_bounty_points }}</p>
<p><strong>Number of questions:</strong><br>{{ profile.number_of_questions_asked }}</p>
<p><strong>Number of replies:</strong><br>{{ profile.number_of_replies }}</p>
<p><strong>Number of answers:</strong><br>{{ profile.number_of_answers }}</p>
<p><strong>Accuracy:</strong><br>{{ accuracy }}</p>
<p><strong>Number of times reported:</strong><br>{{ profile.reported_by_others }}</p>

{% endblock %}

May I know where the value profile is being passed from? Is it from the dictionary {‘profile’: profile_obj} or is it from the context? I tried commenting out both but the template still renders fine.

I have also tried to create a new variable called accuracy in my template but I am unable to get it to render and the template simply fails silently. I then added TEMPLATE_STRING_IF_INVALID = ‘%s’ to my settings file which allowed me to see that the accuracy variable is not found. May I know what I did wrong?

Any advice would be greatly appreciated! 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-05-28T15:56:56+00:00Added an answer on May 28, 2026 at 3:56 pm

    Argh I found the problem! I was changing the wrong file >_< as my python install had written to the default directory.

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

Sidebar

Related Questions

I'm a django newbie and have been having a problem. In my project root
Being a Django newbie, I have a question to ask, which should be very
I'm a complete newbie to Django. I've been trying to get it working on
I am newbie at Django. I have model with a custom method. In view
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
Django newbie here, I have several types of models, in each of them the
Django newbie here, I'm using render_to_response('example.html', { 'error_message': error_message, }, context_instance=RequestContext(request)) How do I
I am a python django newbie, and was going through some open source code,
I'm a Django newbie who needs help: Even though I change some urls in
I am a django newbie and in creating my first project I have come

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.