python - django 页面上的 500 apache 服务器错误,带有联系表
问题描述
我在 django 2.2 中创建了我的第一页。我已经在 apache 服务器上实现了它,但是我在显示带有联系表单的页面时遇到了问题。我收到 500 错误作为响应。我使用 send_mail 函数发送消息。
我检查了服务器日志。不幸的是,他们并没有告诉我太多。我在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 表单 而不是从 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")
推荐阅读
- c# - 如何在指定文本之前和之后获取字符串,然后在 C# 中打印到 txt?
- maven - Maven 仅从 Artifactory 或中央解决工件,而不是两者
- swift - 午睡配置“由关闭错误自行捕获”
- javascript - JavaScript:select1 on-change 填充 select2 中的特定选项(带有 2 个值)
- android - 获取图片名称
- powershell - 使用 icacls 设置文件夹权限
- google-app-engine - 大量使用 ndb 模型会影响性能吗?
- javascript - 要求浏览器探测另一个站点上的数据
- c++ - 从用户定义的头文件调用函数时出现未定义的引用错误,它的实现在 .cpp 文件中
- c - 读取是否超出了 C 中的对象未定义行为?