I have the following urls.py
urlpatterns = patterns('accounts.views',
url(r'^user/(?P<id>\w+)/$', 'profile'),
)
I have the following views.py
def profile(request, id):
user = UserProfile.objects.get(user__username=id)
product = Mattress.objects.filter(owner = id) #PROBLEM IS IN THIS LINE
c = RequestContext(request, {
'action': 'update/',
'button': 'Update',
'profile': user,
'product': product,
})
return render_to_response('registration/user_profile.html', c)
When I type in the url “http://127.0.0.1:8000/user/goelv/”, the id “goelv” is succesfully captured. However, I’m getting the error < invalid literal for int() with base 10: ‘goelv’ > which traces to my views.py in the line product=Mattress.objects.filter(owner = id).
For reference, I have the following models.py where the owner field simply correlates to a User object
class Product(models.Model):
owner = models.ForeignKey(User, null=True, blank=True)
title = models.CharField(max_length=50)
manufacturer = models.CharField(max_length=75)
product_description = models.TextField(max_length=2000)
Can anyone see what I’m doing wrong or how to go about fixing this problem? Thanks for the help!
If you are referring to
id, then it should beintegernot string.However, this would solve your problem.
Note: using
userinstead ofidin filter as you have already retrieved user object.