6.4.用户注册

静态文件的引入

python2写法

<!DOCTYPE html>
<html>
{% load staticfiles %}
<head>
    <link rel="stylesheet" type="text/css" href="{% static 'css/reset.css' %}">
</head>
<body>

</body>

python3写法

<!DOCTYPE html>
<html>
{% load static %}
<head>
    <link rel="stylesheet" type="text/css" href="{% static 'css/reset.css' %}">
</head>
<body>

</body>

验证码组件(django-simple-captcha)

使用指南https://django-simple-captcha.readthedocs.io/en/latest/usage.html

集成django-simple-captcha

  1. 通过 pip install django-simple-captcha安装 django-simple-captcha

  2. settings.pyINSTALLED_APPS 中添加 captcha

  3. 运行python manage.py migrate

  4. 配置 urls.py:

定义表单

To embed a CAPTCHA in your forms, simply add a CaptchaField to the form definition:

定义views

users/views.py

html显示验证码

templates/register.html

邮件发送

邮件设置

hello_django/settings.py

编写邮件工具类

utils/email_send.py

使用邮件工具类

users/views.py

Last updated

Was this helpful?