0

Django 1.10.1

My template is using a mandatory 'title' context variable and an optional 'note' template variable.

Rendering {{ title }} works fine, but rendering {{ note }} causes a full template context to be rendered (kind of debug view?) if note is not defined in the context.

I would expect that is 'note' is not defined in the context it would render an empty string, and if defined renders the content of the variable.

Example:

urls.py:

url(r'^test1', views.testview1),
url(r'^test2', views.testview2),

views.py:

def testview1(request):
    context = {'title': 'My title', 'note': 'my note'}
    return render(request, 'test_template.html', context)


def testview2(request):
    context = {'title': 'My title'}
    return render(request, 'test_template.html', context)

test_template.html:

<h2>{{ title }}</h2>
{{ note }}

testview1 renders as expected:

My title

my note

testview2 renders this unexpected context dump:

My title

[{'False': False, 'None': None, 'True': True}, {u'csrf_token': < SimpleLazyObject: u'ho7MGwEQ86eMVLmHZbDPYE8VLCo3aTAUTM0OAf7Pvr5E8exMKYDqNoTjQGmieLPu'>, 'user': < SimpleLazyObject: < User: user1>>, 'perms': < django.contrib.auth.context_processors.PermWrapper object at 0x113826f50>, 'DEFAULT_MESSAGE_LEVELS': {'DEBUG': 10, 'INFO': 20, 'WARNING': 30, 'SUCCESS': 25, 'ERROR': 40}, 'messages': < django.contrib.messages.storage.fallback.FallbackStorage object at 0x11376b550>, u'request': < WSGIRequest: GET '/swingit/test2'>}, {}, {'title': 'My title'}]

This is the settings.py context related to templates:

DEBUG = True
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates'),
                 os.path.join(BASE_DIR, 'templates', 'allauth')],
        'APP_DIRS': True,
        'OPTIONS': {
            'string_if_invalid': '',
            'context_processors': [
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

These python modules are in the virtual environment:

Babel==2.3.4
BulkSMS==0.3
cGraph==0.1
diff-match-patch==20121119
Django==1.10.1
django-allauth==0.27.0
django-bootstrap-ui==0.2.0
django-bootstrap3==7.0.1
django-crispy-forms==1.6.0
django-debug-toolbar==1.5
django-extensions==1.7.4
django-import-export==0.5.1
django-mailjet==0.2.0
django-phonenumber-field==1.1.0
django-tag-parser==2.1
django-utils==0.0.2
dominate==2.1.17
funcsigs==1.0.2
graphviz==0.5.1
mailjet-rest==1.2.2
MarkupSafe==0.23
mock==2.0.0
nose==1.3.7
oauthlib==2.0.0
pbr==1.10.0
phonenumberslite==7.7.2
pydot2==1.0.33
pygraphviz==1.3.1
pyparsing==2.1.10
python-openid==2.2.5
pytz==2016.7
requests==2.11.1
requests-oauthlib==0.6.2
six==1.10.0
sqlparse==0.2.1
tablib==0.11.2
1
  • Disabled all applications one by one, none of them caused this issue. When I create a new django project this issue is not present, so clearly my project has some misconfiguration somewhere...
    – Davy
    Nov 2, 2016 at 9:57

1 Answer 1

0

One of the python packages had a local change.

So this solved this problem:

pip install -r requirements.txt --ignore-installed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.