From the url I get the username. Now with a help of a username a I also want to get exact User object. Here is my code:
author = UserProfile.objects.get(user.username_iexact = username)
However, I get a error: keyword can't be an expression
How to make it work?
You need something like this:
author = UserProfile.objects.get(user__username__iexact='your_username')
.
Read more at https://docs.djangoproject.com/en/1.7/topics/db/queries/#lookups-that-span-relationships
您需要指定如下( 使用双下划线代替点):
author = UserProfile.objects.get(user__username__iexact=username)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.