栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用django-contact-form(第三方应用程序)?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用django-contact-form(第三方应用程序)?

1.安装

pip install django-contact-form

2.添加必要的配置
settings.py

EMAIL_USE_TLS = True  EMAIL_HOST = 'smtp.gmail.com'  EMAIL_PORT = 587  EMAIL_HOST_USER = 'laike9m@gmail.com'  # this is my email address, use yoursEMAIL_HOST_PASSWORD = os.environ['EMAIL_HOST_PASSWORD']   # set environ yourselfADMINS = (    ('your_name', 'your_email'),   # email will be sent to your_email)MANAGERS = ADMINS

另外,添加

'contact_form'
到中
INSTALLED_APPS

3.创建contact_form模板

在文件夹

contact_form
中创建一个名为的
templates
文件夹,并将以下文件添加到其中:

templates      └─contact_form contact_form.html contact_form.txt contact_form_sent.html contact_form_subject.txt

您可以编写自己的,这是我使用的:

contact_form.html

{% extends 'laike9m_blog/blog_base.html' %}{% block content %}  <h2>Contact Form</h2>  <p>To send us a message fill out the below form.</p>  <form method="post">{% csrf_token %}    <p>Name: <input type="text" name="name"></p>    <p>Your e-mail: <input type="text" name="email"></p>    <p>Message: <textarea name="body" rows="10" cols="50"></textarea></p>    <input type="submit" value="Submit">  </form>{% endblock content %}

contact_form.txt

{{ name }}{{ email }}{{ body }}

contact_form_sent.html

{% extends 'laike9m_blog/blog_base.html' %}{% block content %}  <h2>Your message was sent.</h2>{% endblock content %}

contact_form_subject.txt

message from {{ name }}

4. URLconf

将此行添加到您的URLconf中:

(r'^contact/', include('contact_form.urls')),

全做完了



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/668255.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号