【发布时间】:2021-03-27 05:22:05
【问题描述】:
我有一个部署到 Heroku 的 Django Web 应用程序。 应用已部署且运行良好,但相关问题除外。
一些规格:
- 在我的本地环境中,我使用 SQLite 3 DB
- 在 Heroku 环境中我使用 Postgress DB
当我尝试渲染基于类的视图时,我会遇到此错误:
无法适应类型“SimpleLazyObject”
在对此问题进行了一些检查后,我怀疑它与 User 对象有关。但我不知道如何处理它。
查看代码:
class ProfileListView(LoginRequiredMixin, ListView):
model = Profile
template_name = 'profiles/profile_list.html'
context_object_name = 'qs'
def get_queryset(self):
qs = Profile.objects.get_all_profiles(self.request.user)
return qs
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
return context
网址:
urlpatterns = [
path('', ProfileListView.as_view(), name='all-profiles-view'),
]
自定义管理器:
class ProfileManager(models.Manager):
def get_all_profiles(self, me):
profiles = Profile.objects.all().exclude(user=me)
return profiles
编辑:
问题的根源似乎与:
user = User.objects.get(username__iexact=self.request.user)
【问题讨论】: