Ich benutze Django-Simple-Captcha und es funktioniert gut lokal. Die Seite, auf der sie sich befindet, gibt einen Fehler von 500, sobald sie in Heroku implementiert wurde (der einzige Log-Output, den ich bekomme, ist2017-02-11T13:26:07.367450+00:00 heroku[router]: at=info method=GET path="/contact/" host=fathomless-harbor-1234.herokuapp.com request_id=37555c3c-c468-40cb-a142-c7dd04519e2c fwd="73.163.191.194" dyno=web.1 connect=1ms service=83ms status=500 bytes=386
).
Ich lief die ./manage.py test captcha
und habe drei fehlgeschlagene Tests, von denen alle den ähnlichen Fehler haben File "/Users/pmn/.virtualenvs/within/lib/python2.7/site-packages/django/template/loader.py", line 43, in get_template
raise TemplateDoesNotExist(template_name, chain=chain)
TemplateDoesNotExist: captcha_test/image.html
Ich bin auf Django 1.9.6 und Django-Simple-Captcha 0.5.3
forms.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"
(Hinweis: Wenn ich die beiden Captcha-Zeilen auskommentiere, wird die Seite beim Deploy geladen)
Antworten:
0 für die Antwort № 1Das Problem war, dass die Datenbankmigrationen nicht auf Heroku ausgeführt wurden. heroku run python manage.py makemigrations
und heroku run python manage.py migrate
behoben.