0
Hey, guys, I got a mistake I can’t figure out why. I am creating a simple web client registration app with Django, I am using vscode with text editor.
When I start the application the error described in the question description occurs, only this error happens only when I start using the dupurador of vscode for Django, the error comes from the index.html file where the code line below is:
{% if error_message %}
<div class="alert alert-danger alert-dismissible show" role="alert">
{{ error_message }}
<button type="button" class="close" style="color:white" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>>
{% endif %}
py views.
def index(request):
clients = service_client.get_all() #service_client é uma variavel global que instancia minha classe de serviço
context_view = {'clients':clients}
if 'messages' in request.session:
messages = request.session.pop('messages')
context_view.update(messages)
return render(request, 'core/index.html', context= context_view)
adding messages through the Section
request.session['messages'] = {'success_message':'minha mensagem'}
When I run normally with the remote python Manage.py runserver works normally
Complete error:
Exception has occurred: VariableDoesNotExist
Failed lookup for key [error_message] in [{'True': True, 'False': False, 'None': None}, {'csrf_token': <SimpleLazyObject: <function csrf.<locals>._get_val at 0x07BAD858>>, 'request': <WSGIRequest: GET '/'>, 'user': <SimpleLazyObject: <function AuthenticationMiddleware.process_request.<locals>.<lambda> at 0x07AF9A08>>, 'perms': <django.contrib.auth.context_processors.PermWrapper object at 0x07BD7830>, 'messages': <django.contrib.messages.storage.fallback.FallbackStorage object at 0x07B896D0>, 'DEFAULT_MESSAGE_LEVELS': {'DEBUG': 10, 'INFO': 20, 'SUCCESS': 25, 'WARNING': 30, 'ERROR': 40}}, {}, {'clients': <QuerySet [<Client: Pai Do Pai>, <Client: Pai Do Robson>, <Client: Lucas Moraes Da Silva>]>}, {'block': <Block Node: content. Contents: [<TextNode: '\n\n'>, <IfNode>, <TextNode: '\n\n'>, <IfNode>, <TextNode: '\n <div class="row">\n '>, <ForNode: for c in clients, tail_len: 17>, <TextNode: '\n </tb'>, <django.template.defaulttags.URLNode object at 0x07BA9F90>, <TextNode: '" class="btn btn-success"'>]>}]
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\template\base.py", line 850, in _resolve_lookup
(bit, current)) # missing attribute
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\template\base.py", line 796, in resolve
value = self._resolve_lookup(context)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\template\base.py", line 671, in resolve
obj = self.var.resolve(context)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\template\defaulttags.py", line 875, in eval
return self.value.resolve(context, ignore_failures=True)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\template\defaulttags.py", line 302, in render
match = condition.eval(context)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\template\base.py", line 904, in render_annotated
return self.render(context)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\template\base.py", line 937, in render
bit = node.render_annotated(context)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\template\loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\template\base.py", line 904, in render_annotated
return self.render(context)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\template\base.py", line 937, in render
bit = node.render_annotated(context)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\template\loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\template\base.py", line 904, in render_annotated
return self.render(context)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\template\base.py", line 937, in render
bit = node.render_annotated(context)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\template\base.py", line 163, in _render
return self.nodelist.render(context)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\template\base.py", line 171, in render
return self._render(context)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\template\backends\django.py", line 61, in render
return self.template.render(context)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\template\loader.py", line 62, in render_to_string
return template.render(context, request)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\shortcuts.py", line 36, in render
content = loader.render_to_string(template_name, context, request, using=using)
File "C:\Users\robso\ambientes_virtuais\PainelAdministrativo\cadcli\core\views.py", line 21, in index
return render(request, 'core/index.html', context= context_view)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\views\decorators\http.py", line 40, in inner
return func(request, *args, **kwargs)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\handlers\base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\utils\deprecation.py", line 91, in __call__
response = response or self.get_response(request)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\utils\deprecation.py", line 91, in __call__
response = response or self.get_response(request)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\utils\deprecation.py", line 91, in __call__
response = response or self.get_response(request)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\utils\deprecation.py", line 91, in __call__
response = response or self.get_response(request)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\utils\deprecation.py", line 91, in __call__
response = response or self.get_response(request)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\utils\deprecation.py", line 91, in __call__
response = response or self.get_response(request)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\utils\deprecation.py", line 91, in __call__
response = response or self.get_response(request)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\handlers\base.py", line 78, in get_response
response = self._middleware_chain(request)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\handlers\wsgi.py", line 142, in __call__
response = self.get_response(request)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\contrib\staticfiles\handlers.py", line 65, in __call__
return self.application(environ, start_response)
File "C:\Users\robso\AppData\Local\Programs\Python\Python37-32\Lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\servers\basehttp.py", line 194, in handle_one_request
handler.run(self.server.get_app())
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\servers\basehttp.py", line 169, in handle
self.handle_one_request()
File "C:\Users\robso\AppData\Local\Programs\Python\Python37-32\Lib\socketserver.py", line 720, in __init__
self.handle()
File "C:\Users\robso\AppData\Local\Programs\Python\Python37-32\Lib\socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Users\robso\AppData\Local\Programs\Python\Python37-32\Lib\socketserver.py", line 347, in process_request
self.finish_request(request, client_address)
File "C:\Users\robso\AppData\Local\Programs\Python\Python37-32\Lib\socketserver.py", line 316, in _handle_request_noblock
self.process_request(request, client_address)
File "C:\Users\robso\AppData\Local\Programs\Python\Python37-32\Lib\socketserver.py", line 237, in serve_forever
self._handle_request_noblock()
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\servers\basehttp.py", line 213, in run
httpd.serve_forever()
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\management\commands\runserver.py", line 139, in inner_run
ipv6=self.use_ipv6, threading=threading, server_cls=self.server_cls)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\management\commands\runserver.py", line 104, in run
self.inner_run(None, **options)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\management\commands\runserver.py", line 95, in handle
self.run(**options)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\management\base.py", line 353, in execute
output = self.handle(*args, **options)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\robso\ambientes_virtuais\Painel_administrativo\Lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\robso\ambientes_virtuais\PainelAdministrativo\cadcli\manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\robso\AppData\Local\Programs\Python\Python37-32\Lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\robso\AppData\Local\Programs\Python\Python37-32\Lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\robso\AppData\Local\Programs\Python\Python37-32\Lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
Dude.. I’m not going to try to answer because although I really like the vscode, I did not answer on Jango. For me there is no way to use another editor/ide for python projects other than pycharm, even in the community version.
– Sidon
So Sidon, I’m starting now in python, and I’m seeing the best options also of editors and everything, I have vscode and I really like programming in C# por la, and I saw that you have the option of using in python so I’m saving, but in pycharm it is difficult to have these types of configuration error, because it already comes preconfigured for python projects. Well let’s see if there’s any solution to this in case I don’t have to continue with pycharm anyway.
– Robson Silva
The cool of vscode is that in Django projects it manages to debug, in pycharm only in the professional version.
– Robson Silva
The debug of Django is in the browser itself, just turn on the variable
DEBUG
insettings.py
, it makes no sense to want to debug by IDE (I remember q used only once), if you want an even more powerful debug, install the Django debug Toolbar– Sidon
See if you can’t solve the vscode problem by following this tutorial, if you haven’t already done it
– Sidon