Skip to main content
tracerback
Fonte Link
**Tracerback do Erro**
Traceback (most recent call last):
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/inventarios/views.py", line 103, in inventario_create
    return save_insert(request, form, 'inventario_create.html')
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/inventarios/views.py", line 123, in save_insert
    data['inventario_list'] = render_to_string('inventario_list.html')
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/loader.py", line 62, in render_to_string
    return template.render(context, request)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/base.py", line 171, in render
    return self._render(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/base.py", line 937, in render
    bit = node.render_annotated(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated
    return self.render(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/base.py", line 937, in render
    bit = node.render_annotated(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated
    return self.render(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/base.py", line 937, in render
    bit = node.render_annotated(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated
    return self.render(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/defaulttags.py", line 302, in render
    match = condition.eval(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/defaulttags.py", line 876, in eval
    return self.value.resolve(context, ignore_failures=True)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/base.py", line 698, in resolve
    new_obj = func(obj, *arg_vals)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/inventarios/templatetags/check_permission.py", line 15, in group_permission
    if user.groups.filter(name=grupo):
AttributeError: 'NoneType' object has no attribute 'groups'
**Tracerback do Erro**
Traceback (most recent call last):
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/inventarios/views.py", line 103, in inventario_create
    return save_insert(request, form, 'inventario_create.html')
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/inventarios/views.py", line 123, in save_insert
    data['inventario_list'] = render_to_string('inventario_list.html')
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/loader.py", line 62, in render_to_string
    return template.render(context, request)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/base.py", line 171, in render
    return self._render(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/base.py", line 937, in render
    bit = node.render_annotated(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated
    return self.render(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/base.py", line 937, in render
    bit = node.render_annotated(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated
    return self.render(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/base.py", line 937, in render
    bit = node.render_annotated(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated
    return self.render(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/defaulttags.py", line 302, in render
    match = condition.eval(context)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/defaulttags.py", line 876, in eval
    return self.value.resolve(context, ignore_failures=True)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/venv/lib/python3.7/site-packages/django/template/base.py", line 698, in resolve
    new_obj = func(obj, *arg_vals)
  File "/Users/rodolfosousa/Documents/GitHub/InventoryPortal/inventarios/templatetags/check_permission.py", line 15, in group_permission
    if user.groups.filter(name=grupo):
AttributeError: 'NoneType' object has no attribute 'groups'
Fonte Link

'NoneType' object has no attribute 'groups'

Estou usando uma função na minha TemplateTagsDjango que basicamente verifica se o usuário está no grupo que tem a permissão para o determinado botão.

O retorno 'True ou False' funciona bem, ou seja, ele mostra o botão caso o usuário esteja no grupo, porém ao tentar abrir o botão, eu tenho o seguinte erro no console AttributeError: 'NoneType' object has no attribute 'groups' . Não sei se tem alguma coisa a ver por ser um modal que teria que ser aberto após clicar no botão, pois em outro botão que tem uma função de apenas enviar um e-mail e não muda o usuário de tela, funciona sem erros. Não encontrei na internet nada parecido com meu problema, agradeço qualquer luz.

Minha Função

@register.filter
def group_permission(user, grupo):
if user.groups.filter(name=grupo):
    return True

return False

Meu Template

<nav class="navbar navbar-expand-sm bg-dark navbar-dark sticky-top">
        {% if user|group_permission:'GERENCIA' %}
        <a class="btn btn-success dt-create" data-url="{% url 'inventario_create' %}">Adicionar</a>

        {% endif %}
    </nav>

Minha View

@login_required
def inventario_create(request):
if request.method == 'POST':
    print('entrou no POST do create')
    form = InventarioForm(request.POST)
else:
    form = InventarioForm()
return save_insert(request, form, 'inventario_create.html')

Essa é meu JS que chama o Modal

var ShowForm = function(){
        var btn = $(this);
        $.ajax({
            url: btn.attr("data-url"),
            type: 'get',
            dataType:'json',
            beforeSend: function(data){
                waitingDialog.show('Carregando Inventários', {dialogSize: 'sm', progressType: 'success'})
            },
            success: function(data){
                waitingDialog.hide();
                $('#myModal .modal-content').html(data.html_form);
                $('#myModal').modal('show')
            },
             error: function (error) {
                    console.log(error);
                    alert('error handing here');
              }
        });
    };