AnonymousUser doesn't have attribute '_meta'?!
See original GitHub issueAttributeError: 'AnonymousUser' object has no attribute '_meta'
It’s getting hit at this line
class DisplayActivityActorUrl(Node):
def __init__(self, actor):
self.actor = Variable(actor)
def render(self, context):
actor_instance = self.actor.resolve(context)
# get_for_model has error here
content_type = ContentType.objects.get_for_model(actor_instance).pk
return reverse('actstream_actor', kwargs={
'content_type_id': content_type, 'object_id': actor_instance.pk})
Traceback (most recent call last):
File "/home/gggamers/gggamers/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "./LoLKarma/views.py", line 415, in player_detail
'activities': activities if activities else None,
File "/home/gggamers/gggamers/local/lib/python2.7/site-packages/django/shortcuts/__init__.py", line 44, in render
return HttpResponse(loader.render_to_string(*args, **kwargs),
File "/home/gggamers/gggamers/local/lib/python2.7/site-packages/django/template/loader.py", line 176, in render_to_string
return t.render(context_instance)
File "/home/gggamers/gggamers/local/lib/python2.7/site-packages/django/template/base.py", line 140, in render
return self._render(context)
File "/home/gggamers/gggamers/local/lib/python2.7/site-packages/django/template/base.py", line 134, in _render
return self.nodelist.render(context)
File "/home/gggamers/gggamers/local/lib/python2.7/site-packages/django/template/base.py", line 823, in render
bit = self.render_node(node, context)
File "/home/gggamers/gggamers/local/lib/python2.7/site-packages/django/template/base.py", line 837, in render_node
return node.render(context)
File "/home/gggamers/gggamers/local/lib/python2.7/site-packages/django/template/loader_tags.py", line 123, in render
return compiled_parent._render(context)
File "/home/gggamers/gggamers/local/lib/python2.7/site-packages/django/template/base.py", line 134, in _render
return self.nodelist.render(context)
File "/home/gggamers/gggamers/local/lib/python2.7/site-packages/django/template/base.py", line 823, in render
bit = self.render_node(node, context)
File "/home/gggamers/gggamers/local/lib/python2.7/site-packages/django/template/base.py", line 837, in render_node
return node.render(context)
File "/home/gggamers/gggamers/local/lib/python2.7/site-packages/django/template/loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "/home/gggamers/gggamers/local/lib/python2.7/site-packages/django/template/base.py", line 823, in render
bit = self.render_node(node, context)
File "/home/gggamers/gggamers/local/lib/python2.7/site-packages/django/template/base.py", line 837, in render_node
return node.render(context)
File "/home/gggamers/gggamers/local/lib/python2.7/site-packages/django/template/defaulttags.py", line 281, in render
return nodelist.render(context)
File "/home/gggamers/gggamers/local/lib/python2.7/site-packages/django/template/base.py", line 823, in render
bit = self.render_node(node, context)
File "/home/gggamers/gggamers/local/lib/python2.7/site-packages/django/template/base.py", line 837, in render_node
return node.render(context)
File "/home/gggamers/gggamers/apps/actstream/templatetags/activity_tags.py", line 39, in render
content_type = ContentType.objects.get_for_model(actor_instance).pk
File "/home/gggamers/gggamers/local/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 32, in get_for_model
opts = self._get_opts(model)
File "/home/gggamers/gggamers/local/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 20, in _get_opts
return model._meta.concrete_model._meta
File "/home/gggamers/gggamers/local/lib/python2.7/site-packages/django/utils/functional.py", line 185, in inner
return func(self._wrapped, *args)
AttributeError: 'AnonymousUser' object has no attribute '_meta'
I edited managers.py and am using my own stream
@stream
def model_actions_with_id(self, model, id, **kwargs):
"""
Stream of most recent actions by any particular model
"""
ctype = ContentType.objects.get_for_model(model)
return self.public(
(Q(target_content_type=ctype, target_object_id = id) |
Q(action_object_content_type=ctype, action_object_object_id = id) |
Q(actor_content_type=ctype, action_object_object_id = id)),
**kwargs
)
I use that to select all activities a user was rated in, or all activies in which the user was rated. This is the user displayed on the page, NOT the user viewing the page! I can’t find any reference to request.user
, so I have no idea why it matters that the user is Anonymous! This works perfectly with logged in users.
I am also doing caching for non logged in users which might be doing something… but I have no idea how!!
Issue Analytics
- State:
- Created 11 years ago
- Comments:8
Top Results From Across the Web
Django 'AnonymousUser' object has no attribute '_meta'
I am using social login in my Django app. So, I have added additional backends in my settings.
Read more >'AnonymousUser' object has no attribute '_meta' - Using Django
Hi, I'm having problems with the above error. I am new to Django and learning as I go along. Any help will be...
Read more >Django 'AnonymousUser' object has no attribute '_meta'
Django : Django ' AnonymousUser ' object has no attribute ' _meta ' [ Beautify Your Computer : https://www.hows.tech/p/recommended.html ] Django ...
Read more >'AnonymousUser' object has no attribute '_meta' | Django ...
At registrations sometime works and sometime doesn't and at login works on rare occasions. Also the error is same all the time.
Read more >'AnonymousUser' object has no attribute '_meta' - Reddit
'AnonymousUser' object has no attribute '_meta'. I am working on a user registration form and I keep getting this error when I register...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for your offer to help, my problem was solved since I noticed I haven’t use
set_password
to set the password of a recently registered user, thus when trying to login the user I was getting a AnonymousUser back.For others reading realise what the error says “You’re dealing with an AnonymousUser”, once I thought on this it was clear my login wasn’t working at all.
…I’m not sure about that…