gpt4 book ai didi

python - django-simple-captcha 破坏 Heroku 部署

转载 作者:太空宇宙 更新时间:2023-11-03 15:40:35 25 4
gpt4 key购买 nike

我正在使用 django-simple-captcha,它在本地运行良好。一旦部署到 Heroku,它所在的页面就会出现 500 错误(我得到的唯一日志输出是 (2017-02-11T13:26:07.367450+00:00 heroku[router]: at=info method=GET path= “/contact/”主机=fathomless-harbor-1234.herokuapp.com request_id=37555c3c-c468-40cb-a142-c7dd04519e2c fwd=“73.163.191.194”dyno=web.1连接=1ms服务=83ms状态=500字节= 386)。

我运行了./manage.py测试验证码并得到了三个失败的测试,所有这些都有类似的错误File“/Users/pmn/.virtualenvs/within/lib/python2.7/site-packages/django/template/loader.py”,第 43 行,在 get_template 中
引发 TemplateDoesNotExist(template_name, chain=chain)
TemplateDoesNotExist:captcha_test/image.html

我使用的是 django 1.9.6 和 django-simple-captcha 0.5.3

表单.py

from django import forms
from django.template.loader import get_template
from django.core.mail import EmailMultiAlternatives

from captcha.fields import CaptchaField


class ContactForm(forms.Form):

contact_name = forms.CharField()
contact_email = forms.EmailField()
contact_phone = forms.CharField()
content = forms.CharField(widget=forms.Textarea)
cc_me = forms.BooleanField(required=False, initial=False)
captcha = CaptchaField(required=True)

def send_email(self):
contact_name = self.data["contact_name"]
contact_phone = self.data["contact_phone"]
contact_email = self.data["contact_email"]
content = self.data["content"]

template = get_template("contact.txt")

context = {
"contact_name": contact_name,
"contact_phone": contact_phone,
"contact_email": contact_email,
"content": content,
}

content = template.render(context)
subject, from_email, to = "Inquiry", contact_email, "jason@email.com"
cc_address = contact_email if "cc_me" in self.data else None
email = EmailMultiAlternatives(
subject,
content,
from_email,
["jason@email.com"],
cc=[cc_address],
headers={"Reply-To": contact_email}
)
email.send()

def __init__(self, *args, **kwargs):
super(ContactForm, self).__init__(*args, **kwargs)
for field in self.fields:
self.fields[field].widget.attrs['class'] = 'form-control'

(请注意,如果我注释掉两个验证码行,页面将在部署时加载)

最佳答案

问题是数据库迁移尚未在 Heroku 上运行。 heroku run python manage.py makemigrationsheroku run python manage.py migrate 修复了它。

关于python - django-simple-captcha 破坏 Heroku 部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42176628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com