[英]Django Contact Form Inputs Won't Show Up - Only See Submit Button
I am running into some trouble here as I attempt setting up a contact form on my personal webpage. 我在尝试在个人网页上设置联系表格时遇到了一些麻烦。 For whatever reason I can only see the submit button, the rest of the input fields are not populating.
无论出于什么原因,我只能看到“提交”按钮,其余输入字段均未填充。 Can someone please help?
有人可以帮忙吗? Thanks!
谢谢!
email.html email.html
{% load static %}
{% block content %}
<div id='paddingtop'>
<div class="row" id="title">
<div class="col"><img src='{% static 'personal/img/contactme.png' %}' style="height: 100%; width: 100%; max-width: 530px; max-height: 1000px; min-height:500; min-width: 300px;">
</div>
</div>
</div>
<div class="col" style='margin-top: -40px; max-height: 100%; max-width: 100%;'><hr class='underline'></div>
<div class='email' style='background-color: blue; width: 100%; height: 100%;'>
<form method="post" role="form" action="">
{% csrf_token %}
{{ form.as_p }}
<div class="form-actions">
<button type="submit" style='background-color: red;'>Send</button>
</div>
</form>
</div>
{% endblock %}
forms.py forms.py
from django import forms
class ContactForm(forms.Form):
from_email = forms.EmailField(required=True)
subject = forms.CharField(required=True)
message = forms.CharField(widget=forms.Textarea, required=True)
urls.py urls.py
from django.conf.urls import include, url
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf import settings
from django.conf.urls.static import static
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^home/$', views.index, name='home'),
url(r'^header/$', views.header, name='header'),
url(r'^email/$', views.email, name='email'),
url(r'^success/$', views.success, name='success'),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
views.py views.py
from django import template
from django.conf import settings
from django.core.mail import send_mail, BadHeaderError
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render, redirect
from .forms import ContactForm
def index(request):
return render(request, 'personal/home.html')
def test(request):
return render(request, 'personal/test.html')
def header(request):
return render(request, 'personal/header.html')
# send_email/views.py
def email(request):
if request.method == 'GET':
form = ContactForm()
else:
form = ContactForm(request.POST)
if form.is_valid():
subject = form.cleaned_data['subject']
from_email = form.cleaned_data['from_email']
message = form.cleaned_data['message']
try:
send_mail(subject, message, from_email, ['admin@example.com'])
except BadHeaderError:
return HttpResponse('Invalid header found.')
return redirect('success')
return render(request, "email.html", {'form': form})
def success(request):
return HttpResponse('Success! Thank you for your message.')
Are you using Bootstrap 2? 您正在使用Bootstrap 2吗? Class form-actions exists in Bootstrap 2, doesn't in Bootstrap 3. In addition, I don't know what col class is.
Bootstrap 2中存在类动作 ,而Bootstrap 3中不存在类动作 。此外,我不知道col类是什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.