Getting error with is_popup variable in django 1.9

I always get an error message in the administrator whenever I want to access it, and it is reset since it was deployed to uWSGI. Here's the error:

DEBUG:django.template:Exception while resolving variable 'is_popup' in template 'admin/login.html'. Traceback (most recent call last): File "/home/leandro/.envs/********/lib/python3.4/site-packages/django/template/base.py", line 879, in _resolve_lookup current = current[bit] File "/home/leandro/.envs/*******/lib/python3.4/site-packages/django/template/context.py", line 77, in __getitem__ raise KeyError(key) KeyError: 'is_popup' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/leandro/.envs/********/lib/python3.4/site-packages/django/template/base.py", line 885, in _resolve_lookup if isinstance(current, BaseContext) and getattr(type(current), bit): AttributeError: type object 'RequestContext' has no attribute 'is_popup' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/leandro/.envs/********/lib/python3.4/site-packages/django/template/base.py", line 894, in _resolve_lookup current = current[int(bit)] ValueError: invalid literal for int() with base 10: 'is_popup' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/leandro/.envs/******/lib/python3.4/site-packages/django/template/base.py", line 901, in _resolve_lookup (bit, current)) # missing attribute django.template.base.VariableDoesNotExist: Failed lookup for key [is_popup] in "[{'False': False, 'None': None, 'True': True}, {'MEDIA_URL': '/media/', 'DEFAULT_MESSAGE_LEVELS': {'ERROR': 40, 'WARNING': 30, 'INFO': 20, 'SUCCESS': 25, 'DEBUG': 10}, 'LANGUAGE_CODE': 'es-AR', 'messages': <django.contrib.messages.storage.fallback.FallbackStorage object at 0x7ff93002a8d0>, 'csrf_token': <SimpleLazyObject: <function csrf.<locals>._get_val at 0x7ff92b377d08>>, 'LANGUAGE_BIDI': False, 'TIME_ZONE': 'ART', 'STATIC_URL': '/static/', 'user': <SimpleLazyObject: <django.contrib.auth.models.AnonymousUser object at 0x7ff93002a828>>, 'perms': <django.contrib.auth.context_processors.PermWrapper object at 0x7ff92b324c18>, 'LANGUAGES': [('af', 'Afrikaans'), ('ar', 'Arabic'), ('ast', 'Asturian'), ('az', 'Azerbaijani'), ('bg', 'Bulgarian'), ('be', 'Belarusian'), ('bn', 'Bengali'), ('br', 'Breton'), ('bs', 'Bosnian'), ('ca', 'Catalan'), ('cs', 'Czech'), ('cy', 'Welsh'), ('da', 'Danish'), ('de', 'German'), ('el', 'Greek'), ('en', 'English'), ('en-au', 'Australian English'), ('en-gb', 'British English'), ('eo', 'Esperanto'), ('es', 'Spanish'), ('es-ar', 'Argentinian Spanish'), ('es-co', 'Colombian Spanish'), ('es-mx', 'Mexican Spanish'), ('es-ni', 'Nicaraguan Spanish'), ('es-ve', 'Venezuelan Spanish'), ('et', 'Estonian'), ('eu', 'Basque'), ('fa', 'Persian'), ('fi', 'Finnish'), ('fr', 'French'), ('fy', 'Frisian'), ('ga', 'Irish'), ('gd', 'Scottish Gaelic'), ('gl', 'Galician'), ('he', 'Hebrew'), ('hi', 'Hindi'), ('hr', 'Croatian'), ('hu', 'Hungarian'), ('ia', 'Interlingua'), ('id', 'Indonesian'), ('io', 'Ido'), ('is', 'Icelandic'), ('it', 'Italian'), ('ja', 'Japanese'), ('ka', 'Georgian'), ('kk', 'Kazakh'), ('km', 'Khmer'), ('kn', 'Kannada'), ('ko', 'Korean'), ('lb', 'Luxembourgish'), ('lt', 'Lithuanian'), ('lv', 'Latvian'), ('mk', 'Macedonian'), ('ml', 'Malayalam'), ('mn', 'Mongolian'), ('mr', 'Marathi'), ('my', 'Burmese'), ('nb', 'Norwegian Bokmal'), ('ne', 'Nepali'), ('nl', 'Dutch'), ('nn', 'Norwegian Nynorsk'), ('os', 'Ossetic'), ('pa', 'Punjabi'), ('pl', 'Polish'), ('pt', 'Portuguese'), ('pt-br', 'Brazilian Portuguese'), ('ro', 'Romanian'), ('ru', 'Russian'), ('sk', 'Slovak'), ('sl', 'Slovenian'), ('sq', 'Albanian'), ('sr', 'Serbian'), ('sr-latn', 'Serbian Latin'), ('sv', 'Swedish'), ('sw', 'Swahili'), ('ta', 'Tamil'), ('te', 'Telugu'), ('th', 'Thai'), ('tr', 'Turkish'), ('tt', 'Tatar'), ('udm', 'Udmurt'), ('uk', 'Ukrainian'), ('ur', 'Urdu'), ('vi', 'Vietnamese'), ('zh-hans', 'Simplified Chinese'), ('zh-hant', 'Traditional Chinese')]}, {}, {'next': '/admin/', 'LANGUAGE_BIDI': False, 'available_apps': [], 'title': 'Identificarse', 'site_title': <django.utils.functional.lazy.<locals>.__proxy__ object at 0x7ff9369bd390>, 'site': <Site: example.com>, 'LANGUAGE_CODE': 'es-AR', 'site_name': 'example.com', 'site_url': '/', 'form': <AdminAuthenticationForm bound=False, valid=Unknown, fields=(username;password)>, 'has_permission': False, 'site_header': <django.utils.functional.lazy.<locals>.__proxy__ object at 0x7ff9369bd438>, 'app_path': '/admin/login/?next=/admin/'}]" 

I tried to disable all admin sites that I registered, and I keep getting this error. Any ideas?

+12
django django-admin
source share
3 answers

I also received one log message, with a fresh install of django 1.10.6. and registration is included. I'm not an expert on this, but here's what I found out by asking a question on the Django mailing list.

1) This is a DEBUG message, not a "Error".

As you can read from the Django logbook documentation, the log levels are from lowest priority to highest priority.

  • DEBUG: low level system information for debugging purposes
  • INFO: General System Information
  • WARNING: Information describing a minor problem that has occurred.
  • ERROR: Information describing a serious problem that has occurred.
  • CRITICAL: Information describing a critical problem that has occurred.

This means that it’s actually β€œnice to know” the low level information that you will register if something fails, and you cannot find the reason otherwise.

2) This is about the missing template variable.

If you look at the first line of the exception, then it says

 Exception while resolving variable 'is_popup' in template 'admin/login.html' 

"admin / index.html" extends "base_site.html", which extends "base.html", which has the following lines (near the beginning of the file):

 <body class="{% if is_popup %}popup {% endif %}{% block bodyclass %}{% endblock %}" data-admin-utc-offset="{% now "Z" %}"> <!-- Container --> <div id="container"> {% if not is_popup %} <!-- Header --> <div id="header"> <div id="branding"> {% block branding %}{% endblock %} </div> 

From django documentation

The reason for the missing template variable is that django reuses templates. And in some cases the template variable 'is_popup' will be defined, and django will display the page in different ways. When there is no variable like 'is_popup', django skips related lines. That is, undefined and false identical for comparison purposes within the template file. Of course, you can write code to check if a variable exists, but it will just be an extra line of code. In any case, Django will skip the undefined variable (for example, the try try pattern inside the kernel code).

4) You can easily exclude these exceptions.

Just enable the logger named " django.template " to have only the log level INF.

 'loggers': { 'django': { 'handlers': ['file'], 'level': 'DEBUG', 'propagate': True, }, 'django.template': { 'handlers': ['file'], 'level': 'INFO', 'propagate': True, }, }, 
+21
source share

see SESSION_COOKIE_DOMAIN must match your domain name or parent domain

 SESSION_COOKIE_DOMAIN # maybe it help too SESSION_COOKIE_SECURE 
0
source share

you must set the project logging level not in debug.set for the information to work.

  'loggers': { 'django': { 'handlers': ['file', 'console'], 'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'), 'propagate': True, }, }, 

see https://github.com/django/django/blob/cfda1fa3f8d95f0f4a369da9021dbd770e5fa44a/django/template/base.py#L911

-3
source share

All Articles