用例(Django项目):
我想在我的登录页面上登录->; 因此,我在html(login.html)中使用此表单:
<form class="loginform" action="" method="POST">
{% csrf_token %}
<div class="loginform">
{{form.as_p}}
</div>
<br>
<input type="submit" class="btn btn-success loginbtn" value="Login">
</form>
如果成功登录,我将用DJANGO重定向到以下URL(localhost/welcome/)->; welcome.html:
LOGIN_REDIRECT_URL = "welcome"
我能够使用alertify发送javascript通知,但仅限于使用简单的操作,如单击它或鼠标移动:
function notification(text) {
console.log(text)
alertify.success(text);
}
我在html表单标记中尝试了onsubmit=“javascript:notification(”“)”,但是这只会在URL重定向之前显示。
所以我的问题是:
我真的很感谢你的帮助! 非常感谢!!
Javascript是客户端的。 这意味着,一旦服务器完成了他的呈现过程,您的alertify.success(text);
将在客户端执行。
身份验证过程是服务器端的。 所以您必须让您的服务器使您的alertify成为呈现内容的一部分。
知道了这一点,您只需更改login_redirect_url
内容页面,以便在其中包含对通知的调用:
<!-- your html template comes here -->
<script type="text/javascript">
notification('You are now logged in');
</script>
请记住,每次用户访问此页面时都会显示通知。 您可能希望再次重定向他,或者在Django中引入一个变量以避免再次显示它。