diff --git a/django/template/base.py b/django/template/base.py
index f43194d..7cdee56 100644
a
|
b
|
from functools import partial
|
5 | 5 | from inspect import getargspec |
6 | 6 | |
7 | 7 | from django.conf import settings |
8 | | from django.template.context import (Context, RequestContext, |
| 8 | from django.template.context import (BaseContext, Context, RequestContext, |
9 | 9 | ContextPopException) |
10 | 10 | from django.utils.importlib import import_module |
11 | 11 | from django.utils.itercompat import is_iterable |
… |
… |
class Variable(object):
|
765 | 765 | current = current[bit] |
766 | 766 | except (TypeError, AttributeError, KeyError, ValueError): |
767 | 767 | try: # attribute lookup |
| 768 | # Don't return class attributes if the class is the context: |
| 769 | if (isinstance(current, BaseContext) and |
| 770 | getattr(type(current), bit)): |
| 771 | raise AttributeError |
768 | 772 | current = getattr(current, bit) |
769 | 773 | except (TypeError, AttributeError): |
770 | 774 | try: # list-index lookup |
diff --git a/tests/regressiontests/templates/context.py b/tests/regressiontests/templates/context.py
index 05c1dd5..25692fe 100644
a
|
b
|
|
1 | 1 | # coding: utf-8 |
2 | | from django.template import Context |
| 2 | from django.template import Context, Variable, VariableDoesNotExist |
3 | 3 | from django.utils.unittest import TestCase |
4 | 4 | |
5 | 5 | |
6 | 6 | class ContextTests(TestCase): |
| 7 | |
7 | 8 | def test_context(self): |
8 | 9 | c = Context({"a": 1, "b": "xyzzy"}) |
9 | 10 | self.assertEqual(c["a"], 1) |
… |
… |
class ContextTests(TestCase):
|
14 | 15 | self.assertEqual(c.pop(), {"a": 2}) |
15 | 16 | self.assertEqual(c["a"], 1) |
16 | 17 | self.assertEqual(c.get("foo", 42), 42) |
| 18 | |
| 19 | def test_resolve_on_context_method(self): |
| 20 | # Regression test for #17778 |
| 21 | empty_context = Context() |
| 22 | self.assertRaises(VariableDoesNotExist, |
| 23 | Variable('no_such_variable').resolve, empty_context) |
| 24 | self.assertRaises(VariableDoesNotExist, |
| 25 | Variable('new').resolve, empty_context) |
| 26 | |