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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:44:43+00:00 2026-05-24T07:44:43+00:00

I’m working in Django. In Django, when you’re rendering a template you send it

  • 0

I’m working in Django. In Django, when you’re rendering a template you send it a context dictionary to get replaced. Because I’m lazy/DRY, i often use locals() as a shortcut instead of sending a dictionary that looks like {‘my_var’: my_var, ‘var2’: var2}.

This usually works beautifully, and saves a lot of mind-numbing repetition.

I’m using django-notifications to send emails when certain events happen – say you receive a private message. Django-notifications comes with a built-in queuing feature that I am integrating now.

However, the problem is that django-notifications pickles the context dictionary at queue time. This is where the locals() trick fails — the dictionary from locals has a LOT of crap in it beyond the local variables (e.g. it has import and int()). The dictionary created by locals doesn’t pickle.

I see three options: 1) rewrite the queueing method of django-notifications to render the template before it is stored (straightforward but a bit tedious and breaks upgradability) 2) stop using the locals trick and start repeating myself 3) Try to find a lighter-weight version of locals (or a way to pickle locals).

I’m here hoping someone has leads in the direction of #3.

In case it might be relevant, here is the error I get when I try to pickle using the locals() shortcut:

TypeError: can't pickle ellipsis objects

Further, the dictionary output of locals():

{
    '__builtins__': 
    {
        'bytearray': <type 'bytearray'>,
         'IndexError': <type 'exceptions.IndexError'>,
         'all': <built-in function all>,
         'help': Type help() for interactive help,
         or help(object) for help about object.,
         'vars': <built-in function vars>,
         'SyntaxError': <type 'exceptions.SyntaxError'>,
         'unicode': <type 'unicode'>,
         'UnicodeDecodeError': <type 'exceptions.UnicodeDecodeError'>,
         'isinstance': <built-in function isinstance>,
         'copyright': Copyright (c) 2001-2010 Python Software Foundation.
All Rights Reserved.

Copyright (c) 2000 BeOpen.com.
All Rights Reserved.

Copyright (c) 1995-2001 Corporation for National Research Initiatives.
All Rights Reserved.

Copyright (c) 1991-1995 Stichting Mathematisch Centrum,
         Amsterdam.
All Rights Reserved.,
         'NameError': <type 'exceptions.NameError'>,
         'BytesWarning': <type 'exceptions.BytesWarning'>,
         'dict': <type 'dict'>,
         'input': <built-in function input>,
         'oct': <built-in function oct>,
         'bin': <built-in function bin>,
         'SystemExit': <type 'exceptions.SystemExit'>,
         'StandardError': <type 'exceptions.StandardError'>,
         'format': <built-in function format>,
         'repr': <built-in function repr>,
         'sorted': <built-in function sorted>,
         'False': False,
         'RuntimeWarning': <type 'exceptions.RuntimeWarning'>,
         'list': <type 'list'>,
         'iter': <built-in function iter>,
         'reload': <built-in function reload>,
         'Warning': <type 'exceptions.Warning'>,
         '__package__': None,
         'round': <built-in function round>,
         'dir': <built-in function dir>,
         'cmp': <built-in function cmp>,
         'set': <type 'set'>,
         'bytes': <type 'str'>,
         'reduce': <built-in function reduce>,
         'intern': <built-in function intern>,
         'issubclass': <built-in function issubclass>,
         'Ellipsis': Ellipsis,
         'EOFError': <type 'exceptions.EOFError'>,
         'locals': <built-in function locals>,
         'BufferError': <type 'exceptions.BufferError'>,
         'slice': <type 'slice'>,
         'FloatingPointError': <type 'exceptions.FloatingPointError'>,
         'sum': <built-in function sum>,
         'getattr': <built-in function getattr>,
         'abs': <built-in function abs>,
         'exit': Use exit() or Ctrl-D (i.e. EOF) to exit,
         'print': <built-in function print>,
         'True': True,
         'FutureWarning': <type 'exceptions.FutureWarning'>,
         'ImportWarning': <type 'exceptions.ImportWarning'>,
         'None': None,
         'hash': <built-in function hash>,
         'ReferenceError': <type 'exceptions.ReferenceError'>,
         'len': <built-in function len>,
         'credits':     Thanks to CWI,
         CNRI,
         BeOpen.com,
         Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.,
         'frozenset': <type 'frozenset'>,
         '__name__': '__builtin__',
         'ord': <built-in function ord>,
         'super': <type 'super'>,
         '_': None,
         'TypeError': <type 'exceptions.TypeError'>,
         'license': Type license() to see the full license text,
         'KeyboardInterrupt': <type 'exceptions.KeyboardInterrupt'>,
         'UserWarning': <type 'exceptions.UserWarning'>,
         'filter': <built-in function filter>,
         'range': <built-in function range>,
         'staticmethod': <type 'staticmethod'>,
         'SystemError': <type 'exceptions.SystemError'>,
         'BaseException': <type 'exceptions.BaseException'>,
         'pow': <built-in function pow>,
         'RuntimeError': <type 'exceptions.RuntimeError'>,
         'float': <type 'float'>,
         'MemoryError': <type 'exceptions.MemoryError'>,
         'StopIteration': <type 'exceptions.StopIteration'>,
         'globals': <built-in function globals>,
         'divmod': <built-in function divmod>,
         'enumerate': <type 'enumerate'>,
         'apply': <built-in function apply>,
         'LookupError': <type 'exceptions.LookupError'>,
         'open': <built-in function open>,
         'quit': Use quit() or Ctrl-D (i.e. EOF) to exit,
         'basestring': <type 'basestring'>,
         'UnicodeError': <type 'exceptions.UnicodeError'>,
         'zip': <built-in function zip>,
         'hex': <built-in function hex>,
         'long': <type 'long'>,
         'next': <built-in function next>,
         'ImportError': <type 'exceptions.ImportError'>,
         'chr': <built-in function chr>,
         'xrange': <type 'xrange'>,
         'type': <type 'type'>,
         '__doc__': "Built-in functions,
         exceptions,
         and other objects.\n\nNoteworthy: None is the `nil' object; Ellipsis represents `...' in slices.",
         'Exception': <type 'exceptions.Exception'>,
         'tuple': <type 'tuple'>,
         'UnicodeTranslateError': <type 'exceptions.UnicodeTranslateError'>,
         'reversed': <type 'reversed'>,
         'UnicodeEncodeError': <type 'exceptions.UnicodeEncodeError'>,
         'IOError': <type 'exceptions.IOError'>,
         'hasattr': <built-in function hasattr>,
         'delattr': <built-in function delattr>,
         'setattr': <built-in function setattr>,
         'raw_input': <built-in function raw_input>,
         'SyntaxWarning': <type 'exceptions.SyntaxWarning'>,
         'compile': <built-in function compile>,
         'ArithmeticError': <type 'exceptions.ArithmeticError'>,
         'str': <type 'str'>,
         'property': <type 'property'>,
         'GeneratorExit': <type 'exceptions.GeneratorExit'>,
         'int': <type 'int'>,
         '__import__': <built-in function __import__>,
         'KeyError': <type 'exceptions.KeyError'>,
         'coerce': <built-in function coerce>,
         'PendingDeprecationWarning': <type 'exceptions.PendingDeprecationWarning'>,
         'file': <type 'file'>,
         'EnvironmentError': <type 'exceptions.EnvironmentError'>,
         'unichr': <built-in function unichr>,
         'id': <built-in function id>,
         'OSError': <type 'exceptions.OSError'>,
         'DeprecationWarning': <type 'exceptions.DeprecationWarning'>,
         'min': <built-in function min>,
         'UnicodeWarning': <type 'exceptions.UnicodeWarning'>,
         'execfile': <built-in function execfile>,
         'any': <built-in function any>,
         'complex': <type 'complex'>,
         'bool': <type 'bool'>,
         'ValueError': <type 'exceptions.ValueError'>,
         'NotImplemented': NotImplemented,
         'map': <built-in function map>,
         'buffer': <type 'buffer'>,
         'max': <built-in function max>,
         'object': <type 'object'>,
         'TabError': <type 'exceptions.TabError'>,
         'callable': <built-in function callable>,
         'ZeroDivisionError': <type 'exceptions.ZeroDivisionError'>,
         'eval': <built-in function eval>,
         '__debug__': True,
         'IndentationError': <type 'exceptions.IndentationError'>,
         'AssertionError': <type 'exceptions.AssertionError'>,
         'classmethod': <type 'classmethod'>,
         'UnboundLocalError': <type 'exceptions.UnboundLocalError'>,
         'NotImplementedError': <type 'exceptions.NotImplementedError'>,
         'AttributeError': <type 'exceptions.AttributeError'>,
         'OverflowError': <type 'exceptions.OverflowError'>
    },
     'notification': <module 'notification.models' from '/home/b/webapps/myapp/notification/models.pyc'>,
     'u': <User: abcd>,
     'User': <class 'django.contrib.auth.models.User'>
}
  • 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-24T07:44:44+00:00Added an answer on May 24, 2026 at 7:44 am

    No. Its worth repeating yourself if you are going to pickle. Lots of objects, some of them unintuitive, are unable to be pickled (i.e. form input).

    The locals() shortcut should only be used when you are certain that the template will be rendered immediately.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.