如何创建一个受密码保护的帖子页面

时间:2020-07-26 15:29:18

标签: python django django-views

因此,我已经开发了django的网站,现在一切正常。但是我要发表一篇受密码保护的帖子,这意味着您需要输入密码才能查看帖子的内容。我在互联网上搜索,但实际上没有找到一种方法,其中一些建议的硬代码带有密码。我想要更动态的地方,您可以在带有密码保护选项的管理帖子页面中进行编辑。类似于问题here

1 个答案:

答案 0 :(得分:0)

def password_protected_post(request):
    if request.mothod == 'POST':
        form = passwordform(request.POST)
        if form.is_valid():
            password = form.cleaned_data['password']
            if password == my_password:
                 return 'the content you want to show'
    else:
       ....'show the passwordform'