[Fixed]-Django Python: invalid literal for int() with base 10: 'arcetina'

1👍

As the error says, you’re passing a string to filter a field that is an integer. (Actually it’s a foreign key, but that is stored as an integer ID.)

If you want to filter on a field in the related model, you need to use the double-underscore syntax:

posts = Post.objects.filter(author__username=components[0])

Note also that it’s an extremely bad idea to have a global posts queryset, especially as you’re mutating it in your view. All requests will see the same list; once you’ve filtered it by user, or reversed it, the next request will see the already-modified queryset. You should remove the global variable and query the Posts model from scratch each time.

Leave a comment