如何使用django-contact-form(第三方应用)? [英] How to use django-contact-form (third-party app)?

查看:192
本文介绍了如何使用django-contact-form(第三方应用)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

django-contact-form 是受欢迎的第三方应用程序。它旨在通过为Django动力站点提供简单,可扩展的联系表单功能来消除繁琐和重复。但是,我发现文档难以跟踪(也许我不够聪明:)。

django-contact-form is a popular third-party application. It aims to remove tedium and repetition by providing simple, extensible contact-form functionality for Django-powered sites. However I found the documentation is somehow difficult to follow(Perhaps I'm not clever enough:).

经过一些搜索和测试,最后我得到它的工作。我会写下这些步骤和代码,以帮助未来可能使用它们的人。

After some searching and testing, finally I got it to work. I'll write down the steps and code to help those who might be using it in the future.

推荐答案

1。安装



1. Install

pip install django-contact-form



2。将必要的配置添加到 settings.py



2. Add necessary configuration to 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 yours
EMAIL_HOST_PASSWORD = os.environ['EMAIL_HOST_PASSWORD']   # set environ yourself

ADMINS = (
    ('your_name', 'your_email'),   # email will be sent to your_email
)

MANAGERS = ADMINS

另外,添加'contact_form'到您的 INSTALLED_APPS

模板中创建名为 contact_form 的文件夹文件夹并将这些文件添加到其中:

Create a folder called contact_form in your templates folder and add these files into it:

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

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

You can write your own, Here's what I use:

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 / p>

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 / p>

contact_form_subject.txt

message from {{ name }}



4。 URLconf



将此行添加到URLconf中:

4. URLconf

Add this line into your URLconf:

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

/ strong>

All Done

这篇关于如何使用django-contact-form(第三方应用)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆