简体   繁体   English

500 django 页面上的 apache 服务器错误,带有联系表格

[英]500 apache server error on django page with contact form

I create my first page in django 2.2.我在 django 2.2 中创建了我的第一页。 I have implemented it on the apache server, but I have a problem displaying the page with the contact form.我已经在 apache 服务器上实现了它,但是我在显示带有联系表单的页面时遇到了问题。 I receive a 500 error in response.我收到 500 错误作为响应。 I use the send_mail function to send messages.我使用 send_mail function 发送消息。

I checked the server logs.我检查了服务器日志。 Unfortunately they don't tell me much.不幸的是,他们并没有告诉我太多。 I added the {% csrf_token%} tag under the form tag in the html code.我在 html 代码的 form 标签下添加了 {%csrf_token%} 标签。 I think the problem is because of the wrong view for the page, but I don't know what to do to fix it.我认为问题是由于页面的错误视图,但我不知道该怎么做才能修复它。

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")

Below, I paste the apache server log:下面,我贴上 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"]

Some changes you need to have: You need to make sure that the request is POST before using post data and also better use the django forms instead of taking inputs from POST request您需要进行一些更改:您需要在使用发布数据之前确保请求是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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM