1.報錯信息:
原因在jquery.js中沒有引入jquery.cookie.js,HTML代碼:
1 {% load static %} 2 <!DOCTYPE html> 3 <html lang="en"> 4 <head> 5 <meta charset="UTF-8"> 6 <title>Login</title> 7 </head> 8 <body> 9 <form action="{% url 'login' %}" method="post"><!--url指定提交數據地址,待校驗數據的def--> 10 {% csrf_token %}<!--通過csrf認證機制--> 11 用戶名:<input type="text" name="username"> 12 密 碼:<input type="password" name="password"> 13 <input type="submit" value="提交"> 14 </form> 15 <script src="{% static 'jquery-3.4.1.js' %}"></script> 16 </body> 17 </html>
2.在jquery后引入juqery.cookie.js
1 {% load static %} 2 <!DOCTYPE html> 3 <html lang="en"> 4 <head> 5 <meta charset="UTF-8"> 6 <title>Login</title> 7 </head> 8 <body> 9 <form action="{% url 'login' %}" method="post"><!--url指定提交數據地址,待校驗數據的def--> 10 {% csrf_token %}<!--通過csrf認證機制--> 11 用戶名:<input type="text" name="username"> 12 密 碼:<input type="password" name="password"> 13 <input type="submit" value="提交"> 14 </form> 15 <script src="{% static 'jquery-3.4.1.js' %}"></script> 16 <script src="{% static 'jquery.cookie.js' %}"></script> 17 18 </body> 19 </html>