簡體   English   中英

500 django 頁面上的 apache 服務器錯誤,帶有聯系表格

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM