发生VsCode异常:VariableDoesNotExist

时间:2019-04-03 08:42:00

标签: django visual-studio-code

使用调试器运行Django时,VS Code引发异常。

我在之前运行良好的两个不同项目上遇到了同样的问题。我不记得会导致此异常的任何更改。当我尝试打开Django管理页面时发生。

例外:

Exception has occurred: VariableDoesNotExist
Failed lookup for key [is_popup] in [{'True': True, 'False': False, 'None': None}, {'csrf_token': <SimpleLazyObject: '1XjSoBrvAaFZuOY9WTme5tXLO8awl43ORBO5YolUoHOlM0nOLDAfGd0atO3kh3dI'>, 'debug': True, 'sql_queries': <function debug.<locals>.<lambda> at 0x109638c80>, 'request': <WSGIRequest: GET '/login/?next=/'>, 'user': <SimpleLazyObject: <django.contrib.auth.models.AnonymousUser object at 0x1095d3908>>, 'perms': <django.contrib.auth.context_processors.PermWrapper object at 0x1095d3550>, 'messages': <django.contrib.messages.storage.fallback.FallbackStorage object at 0x1095d3c50>, 'DEFAULT_MESSAGE_LEVELS': {'DEBUG': 10, 'INFO': 20, 'SUCCESS': 25, 'WARNING': 30, 'ERROR': 40}}, {}, {'form': <AdminAuthenticationForm bound=False, valid=Unknown, fields=(username;password)>, 'view': <django.contrib.auth.views.LoginView object at 0x1095d3940>, 'site_title': 'Administration', 'site_header': 'Meridia ETL', 'site_url': '/', 'has_permission': False, 'available_apps': [], 'title': 'Log in', 'app_path': '/login/?next=/', 'username': '', 'next': '/', 'site': <django.contrib.sites.requests.RequestSite object at 0x1095d35f8>, 'site_name': 'localhost:8000', 'LANGUAGE_CODE': 'en-us', 'LANGUAGE_BIDI': False}]
  File "/Users/macbook/Development/MERIDIA/meridiaETLproject/env/lib/python3.7/site-packages/django/template/base.py", line 850, in _resolve_lookup
    (bit, current))  # missing attribute
  File "/Users/macbook/Development/MERIDIA/meridiaETLproject/env/lib/python3.7/site-packages/django/template/base.py", line 796, in resolve
    value = self._resolve_lookup(context)
  File "/Users/macbook/Development/MERIDIA/meridiaETLproject/env/lib/python3.7/site-packages/django/template/base.py", line 671, in resolve
    obj = self.var.resolve(context)
  File "/Users/macbook/Development/MERIDIA/meridiaETLproject/env/lib/python3.7/site-packages/django/template/defaulttags.py", line 875, in eval
    return self.value.resolve(context, ignore_failures=True)
  File "/Users/macbook/Development/MERIDIA/meridiaETLproject/env/lib/python3.7/site-packages/django/template/defaulttags.py", line 302, in render
    match = condition.eval(context)
  File "/Users/macbook/Development/MERIDIA/meridiaETLproject/env/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated
    return self.render(context)
  File "/Users/macbook/Development/MERIDIA/meridiaETLproject/env/lib/python3.7/site-packages/django/template/base.py", line 937, in render
    bit = node.render_annotated(context)
  File "/Users/macbook/Development/MERIDIA/meridiaETLproject/env/lib/python3.7/site-packages/django/test/utils.py", line 96, in instrumented_test_render
    return self.nodelist.render(context)
  File "/Users/macbook/Development/MERIDIA/meridiaETLproject/env/lib/python3.7/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/Users/macbook/Development/MERIDIA/meridiaETLproject/env/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated
    return self.render(context)
  File "/Users/macbook/Development/MERIDIA/meridiaETLproject/env/lib/python3.7/site-packages/django/template/base.py", line 937, in render
    bit = node.render_annotated(context)
  File "/Users/macbook/Development/MERIDIA/meridiaETLproject/env/lib/python3.7/site-packages/django/test/utils.py", line 96, in instrumented_test_render
    return self.nodelist.render(context)
  File "/Users/macbook/Development/MERIDIA/meridiaETLproject/env/lib/python3.7/site-packages/django/template/loader_tags.py", line 150, in render

仅当我在以下Launch.json设置中使用调试器时才会发生

{
            "name": "Django",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/manage.py",
            "console": "integratedTerminal",
            "args": [
                "runserver",
                "--noreload",
                // "--nothreading",
                // "--settings=bouncer.settings.development"
            ],
            "django": true
        }

它可以与python manage.py runserver一起正常工作

操作系统:MacOS Mojave 10.14

Django:2.1.1

VS代码:1.32.3

1 个答案:

答案 0 :(得分:2)

似乎只有在检查默认断点Uncaught Exception时,调试器才会引发异常。

enter image description here

因此解决方法只是使其不受检查。