[英]500 apache server error on django page with contact form
我在 django 2.2 中创建了我的第一页。 我已经在 apache 服务器上实现了它,但是我在显示带有联系表单的页面时遇到了问题。 我收到 500 错误作为响应。 我使用 send_mail function 发送消息。
我检查了服务器日志。 不幸的是,他们并没有告诉我太多。 我在 html 代码的 form 标签下添加了 {%csrf_token%} 标签。 我认为问题是由于页面的错误视图,但我不知道该怎么做才能修复它。
def contact(request):
message = request.POST.get('message', False)
sender = request.POST.get('email', False)
subject = "New message from example.com from: " + sender
send_mail(subject, message, 'contact@example2.com', ['contact@example3.com'], fail_silently=False)
return render(request=request, template_name="main/contact.html")
下面,我贴上 apache 服务器日志:
[Thu Oct 24 10:47:28.394512 2019] [:error] [pid 17558] [client x.x.x.x] ModSecurity: Warning. Pattern match "^5\\\\d{2}$" at RESPONSE_STATUS. [file "/usr/share/modsecurity-crs/activated_rules/modsecurity_crs_50_outbound.conf"] [line "53"] [id "970901"] [rev "2"] [msg "The application is not available"] [data "Matched Data: 500 found within RESPONSE_STATUS: 500"] [severity "ERROR"] [ver "OWASP_CRS/2.2.9"] [maturity "9"] [accuracy "9"] [tag "WASCTC/WASC-13"] [tag "OWASP_TOP_10/A6"] [tag "PCI/6.5.6"] [hostname "example.com"] [uri "/contact/"] [unique_id "XbFlIH8AAQEAAESWGb4AAAAA"]
[Thu Oct 24 10:47:28.397631 2019] [:error] [pid 17558] [client x.x.x.x] ModSecurity: Warning. Operator GE matched 4 at TX:outbound_anomaly_score. [file "/usr/share/modsecurity-crs/activated_rules/modsecurity_crs_60_correlation.conf"] [line "40"] [id "981205"] [msg "Outbound Anomaly Score Exceeded (score 4): The application is not available"] [hostname "example.com"] [uri "/contact/"] [unique_id "XbFlIH8AAQEAAESWGb4AAAAA"]
您需要进行一些更改:您需要在使用发布数据之前确保请求是POST
,并且最好使用django forms而不是从 POST 请求中获取输入
def contact(request):
if request.method == 'POST'
message = request.POST.get('message', False)
sender = request.POST.get('email', False)
subject = "New message from example.com from: " + sender
send_mail(subject, message, 'contact@example2.com', ['contact@example3.com'], fail_silently=False)
return render(request=request, template_name="main/contact.html")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.