0

I get this error after installing a component into a project running django 2.1 :


int() argument must be a string, a bytes-like object or a number, not 'SimpleLazyObject'

view

class TrackLikeToggle(RedirectView):
    def get_redirect_url(self, *args, **kwargs):
        id = self.kwargs.get("id")
        obj = get_object_or_404(Post, id=id)
        url_ = obj.get_absolute_url()
        user = self.request.user
        if user in obj.likes.all():
            obj.likes.remove(user)
        else:
            messages.add_message(self.request, messages.INFO, '1')
            obj.likes.add(user)
        return url_

Full Traceback: https://pastebin.com/FmkFKDW3


Thank you very much

  • Traceback doesn't help much. When you get the error? you can print after each line and sen how far the code goes you can use a debugger for it. – Navid Zarepak Dec 18 '19 at 18:30

1 Answers1

0

I think this is because

When obj.likes.add(user) line of code being hit, The user is not somehow authenticated, Which returns Django's default request user object, which is an instance of SimpleLazyObject. You can either make the view as login_required or you can try to check whether the user is authenticated at the point or not.

For more details on this you can follow thisLink

Akhil Suresh
  • 151
  • 9