我有以下 urls.py
urlpatterns = patterns('accounts.views',
url(r'^user/(?P<id>\w+)/$', 'profile'),
)
我有以下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)
当我输入网址“http://127.0.0.1:8000/user/goelv/”时,ID“goelv”被成功捕获。但是,我收到错误 <invalid literal for int() with base 10: 'goelv' > 这可以追溯到我在行 product=Mattress.objects.filter(owner = id) 中的 views.py。
作为参考,我有以下 models.py ,其中所有者字段仅与用户对象相关
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)
谁能看到我做错了什么或如何解决这个问题?谢谢您的帮助!