[Answered ]-Invalid literal for int() with base 10: 'n'

1๐Ÿ‘

โœ…

You have problem with this piece of code in your view.

Following.objects.get(follow_to=follow_to)

Here the follow_to parameter passed to view is string and from the url mentioned it seems it is 'n'. But you are searching for foreign key which will search for id of an object. id is integer.

So in the query its trying to convert 'n' into int to search appropriate object. But the conversion fails.

You need to either check for that and/or use id related regex in url for follow_to parameter.

๐Ÿ‘คRohan

1๐Ÿ‘

If the django.contrib.auth.models.User model is used, its pk is an integer. However, the url pattern matches any word character (\w). Thus if only numbers should be allowed, modifying urls.py to only allow integer id matches might be a solution.

url(r'^followed/(?P<follow_to>\d+)/$', followed, name='followed'),
๐Ÿ‘คzsepi

Leave a comment