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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:50:59+00:00 2026-05-27T15:50:59+00:00

I have a user profile model with user(ForeignKey) and user_timezone(CharField). On my template page

  • 0

I have a user profile model with user(ForeignKey) and user_timezone(CharField). On my template page there’s a drop down box that lets the user select their timezone, they submit and everything works fine. Except for the fact that I have to hard code the pk. I can’t seem to figure out how to get the current user?

import pytz
import datetime
import time
from pytz import timezone
from django import template
from django.contrib.auth.models import User
from turnover.models import UserProfile
from django.shortcuts import get_object_or_404

register = template.Library()

class TimeNode(template.Node):
    def __init__(self, format_string):
        self.format_string = format_string

    def render(self, context):
        # Get the user profile and their timezone
        profile = UserProfile.objects.get(pk=99) #<------ Hard Coded--
        set_user_timezone = profile.user_timezone

        # Set the Timezone
        dt = datetime.datetime.fromtimestamp(time.time(), pytz.utc)
        get_timezone = pytz.timezone(u'%s' % set_user_timezone)
        profile_timezone = get_timezone.normalize(dt.astimezone(get_timezone)).strftime(self.format_string)
        return profile_timezone

    @register.tag(name="current_time")
    def current_time(parser, token):
        tag_name, format_string = token.split_contents()
        return TimeNode(format_string[1:-1])
  • 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-27T15:50:59+00:00Added an answer on May 27, 2026 at 3:50 pm
    request = context.get('request')
    user = request.user
    

    But you should have in settings:

    TEMPLATE_CONTEXT_PROCESSORS = (
        ...
        'django.core.context_processors.request',
        ...
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my CakePHP 1.2.5 app, I have a Profile model that belongsTo a User
I have a simple question. This is my profile: class Profile(models.Model): user = models.ForeignKey(User,
I have two models Profile and Avatar. models.py class Profile(models.Model): user = models.ForeignKey(User) profile_name
I have a profile. class UserProfile(models.Model): user = models.ForeignKey(User, related_name=%(class)s, unique=True) providers = models.ManyToManyField(ServiceProvider,
I have a model as follows class UserPrivacy(models.Model): user = models.ForeignKey(User) profile = models.SmallIntegerField(default=1,
I have a user profile page on my web app which has contact information.
Dear all, I have a question about Facebook Page: ( NOT user profile page,
I have many many small images that are displayed on a user's profile and
I have a database that hold's a user's optional profile. In the profile I
Given these two models: class Profile(models.Model): user = models.ForeignKey(User, unique=True, verbose_name=_('user')) about = models.TextField(_('about'),

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.