首先,如果我不清楚我想做什么,或者如果我没有提供足够的信息,我对Django/Python还是比较陌生的。你知道吗
我目前有一个视图,呈现类似博客文章的内容:
class SingleCharacter(LoginRequiredMixin,generic.DetailView):
model = models.Character
def get_context_data(self, **kwargs):
context = super(SingleCharacter, self).get_context_data(**kwargs)
return context
在这个视图的模板中,我有一个模板标记,用于检查用户是否经过身份验证以及帖子的所有者:
{% if user.is_authenticated and user == character.user %}
但是,我目前正在将xhtml2pdf合并到我的项目中,这种只将文章保护给创建它的用户的方法引起了一些问题。你知道吗
我想知道是否有可能移动user.u是否经过身份验证和用户==字符.用户如果是的话,我可以用一个简单的if语句来实现吗?你知道吗
class SingleCharacter(LoginRequiredMixin,generic.DetailView):
model = models.Character
if user.is_authenticated and user == character.user:
def get_context_data(self, **kwargs):
context = super(SingleCharacter, self).get_context_data(**kwargs)
return context
else:
<I'll include some redirect to a 404 page>
我想看看有没有别的办法,但我想我会把这个扔给更有经验的人,希望能弄明白。你知道吗
谢谢你的帮助!你知道吗
您可以重写DetailView的
get
方法,并在那里处理逻辑:我认为您可以在中创建一个CustomPermissionMixin,并将其用作
相关问题 更多 >
编程相关推荐