我有一个用户注册,在单击发送到用户电子邮件地址的令牌链接后,用户的帐户被激活。如果 24 小时内未单击特定链接,我希望使链接过期并从数据库中删除其数据。
我在一处读到,该链接在 48 小时后过期,对吗?
这是我的问题-
如何自动删除24小时内没有点击激活链接的用户?
(到目前为止,我可以通过进入管理面板并检查电子邮件是否已确认来做到这一点)
这是我的激活功能,
def activate(request, uidb64, token):
try:
uid = force_text(urlsafe_base64_decode(uidb64))
user = User.objects.get(pk=uid)
except (TypeError, ValueError, OverflowError, ObjectDoesNotExist):
user = None
if user is not None and account_activation_token.check_token(user, token):
user.is_active = True
user.email_confirmed = True
user.save()
login(request, user)
return redirect('home')
else:
return render(request, 'user/account_activation_invalid.html')
Run Code Online (Sandbox Code Playgroud)
这是我的 tokens.py 创建令牌,
from django.contrib.auth.tokens import PasswordResetTokenGenerator
from django.utils import six
class AccountActivationTokenGenerator(PasswordResetTokenGenerator):
def _make_hash_value(self, user, timestamp):
return (
six.text_type(user.pk) +
six.text_type(timestamp) +
six.text_type(user.email_confirmed)
)
account_activation_token = …Run Code Online (Sandbox Code Playgroud) 我正在设计我的登录页面。我添加了按钮背景色,该背景色完美地显示在chrome和firefox上,但是在Microsoft Edge上却不显示。以下是我的HTML和CSS,请注意-我尝试了多种颜色,所有颜色都在chrome和firefox上运行,但不在边缘
的HTML
.index-un-right-nav-buttom{
float: left;
height: auto;
padding-top: 10px;
padding-bottom: 10px;
width: 100%;
}
.index-un-right-nav-submit-button{
float: left;
padding-top: 5px;
padding-bottom: 5px;
height: 50px;
width: 100px;
margin-top: 20px;
margin-bottom: 20px;
margin-left: 10%;
border: none;
outline: none;
color: #ffffff;
background-color: #007182fb;
font-family: Arial, Helvetica, sans-serif;
font-size: 18px;
border-radius: 50px;
}Run Code Online (Sandbox Code Playgroud)
<span class="index-un-right-nav-button">
<button class="index-un-right-nav-submit-button">Login</button>
</span>
Run Code Online (Sandbox Code Playgroud)
这是我在 models.py 中生成 slug 的代码,
def save(self):
self.slug = slugify(self.title)
super(Post, self).save()
Run Code Online (Sandbox Code Playgroud)
我想检查该 slug 是否已存在于我的数据库中,然后仅将 id 添加到该 slug 中。
我现在能想到的唯一方法是通过这样做在每个 slug 中添加 id,
def save(self):
super(Post, self).save()
if not self.slug:
self.slug = slugify(self.title) + "-" + str(self.id)
self.save()
Run Code Online (Sandbox Code Playgroud)
问题是,它在所有 slugs 中添加了 id。
那么我如何检查由于相同标题而导致的 slug 是否已存在,然后仅将 id 添加到新的 slug 中?