django-contact-form实际上没有发送,看起来很好

时间:2015-06-15 02:25:35

标签: python django forms

我一直在使用django-contact-form在我的个人网站上提供简单的联系表格。一切都很好,但表格不提交。我不明白为什么,并开始变得非常恶化。任何帮助将不胜感激。我的代码如下。

此外,this非常有帮助。实际文档是here

我错过了什么?

项目结构:

dev_website
    contact_form
        contact_form_sent.html
    django-contact-form-1.0
    personal_website
        templates
            contact_form
                contact_form.html
                contact_form.txt
                contact_form_sent.html
                contact_form_subject.txt
            personal_website
                base.html
                bio.html
                blog.html
                index.html
                music.html
                webdev.html
        __init__.py
        forms.py
        models.py
        settings.py
        tests.py
        urls.py
        views.py
    mysite
        __init__.py
        local_settings.py
        settings.py
        urls.py
        wsgi.py
    static
        css
            personal_website.css
        fonts
        images
            header.png

personal_website / settings.py& mysite / settings.py:

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ''

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

 INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'personal_website',
    'contact_form',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'mysite.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
           'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'mysite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'America/New_York'

USE_I18N = True

USE_L10N = True

USE_TZ = False


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/

STATIC_URL = '/static/'

# import dj_database_url
# DATABASES['default'] = dj_databases_url.config()

SECURY_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

ALLOWED_HOSTS = ['*']

STATIC_ROOT = 'staticfiles'

DEBUG = True

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
    "/home/personal_webiste/static/images/header.png",
)

TEMPLATE_DIRS = (
    "/home/website/personal_website/templates/dobweb/index.html",
    "/home/website/personal_website/templates/dobweb/music.html",
    "/home/website/personal_website/templates/dobweb/webdev.html",
    "/home/website/personal_website/templates/dobweb/thanks.html"
    "/home/website/personal_website/templates/dobweb/blog.html",
    "/home/website/personal_website/templates/contact_form/contact_form.html",
)

LOGIN_REDIRECT = '/'

# Contact Form specifics
EMAIL_USE_TLS = True
EMAIL_HOST = 'imcgrunt.asoshared.com'
EMAIL_PORT = 465
EMAIL_HOST_USER = 'me@personalwebsite.com'
EMAIL_HOST_PASSWORD = 'password'
#DEFAULT_FROM_EMAIL = 'me@personalwebsite.com'

ADMINS = (
    ('me lastname', 'me@personalwebsite.com'),
)

MANAGERS = ADMINS
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

personal_website / contact_form / contact_form.html:

{% extends 'personal_website/base.html' %}

{% block content %}
    <p><br></p>
    <p><br></p>
    <h3>Contact me</h3>
    <p>You can send me a message via the contact form below.</p>
    <form method="post">{% csrf_token %}
        <p>Your name: <input type="text" name="name"> Your email: <input type="text" name="email"></p>
        <p>Message:</p>
        <p><textarea name="body" rows="10" cols="50"></textarea></p>
        <input type="submit" value="Send">
    </form>
{% endblock %}

personal_website / urls.py:

from django.conf.urls import patterns, include, url
from django.contrib import admin
from . import views

urlpatterns = patterns('',
    url(r'^contact/', include('contact_form.urls'), name='contact'),
    url(r'^$', views.index),
    url(r'^music/$', views.music, name='music'),
    url(r'^webdev/$', views.webdev, name='webdev'),
    url(r'^bio/$', views.bio, name='bio'),
    url(r'^blog/$', views.blog, name='blog'),
    url(r'^admin/', include(admin.site.urls)),
)

personal_website / forms.py:

from django import forms


class ContactForm(forms.Form):
    subject = forms.CharField(max_length=100)
    message = forms.CharField(widget=forms.Textarea)
    sender = forms.EmailField()
    cc_myself = forms.BooleanField(required=True)

0 个答案:

没有答案