Django如何分配用于将电子邮件发送到HTML按钮的功能

问题描述 投票:0回答:1

我是django的新手,我想知道如何将功能“ Initial_Report(request):”赋予html按钮,以便每次单击它都能执行给定的功能。

查看代码

def home(request):

return render(request, 'home.html')

def Initial_Report(request):

noc_emails = Employee.objects.exclude(Position__Position__contains='Customer').values_list('Email', flat=True)
cs_emails = Employee.objects.filter(Position__Position__contains = 'Customer').values_list('Email', flat=True)

noc_message = ('Initial Outage Report', 'This is a new outage report ,The information is in the document', '[email protected]', noc_emails)
cs_message = ('Initial Outage Report', 'This is a new outage report ,The information is in the document', '[email protected]', cs_emails)
send_mass_mail((noc_message,cs_message), fail_silently=False)

return render(request,'InitialReport.html')

网址

urlpatterns = [

path('', views.home, name='home.html'),
path('admin/', admin.site.urls),
path('Initial_Report', views.Initial_Report, name = 'Initial_Report' ),

]

Home.html

<button> Send Initial Report</button>
html django button
1个回答
0
投票

因为触发/ Initial_Report时调用了Initial_Report

path('Initial_Report', views.Initial_Report, name = 'Initial_Report' ),

您可以将链接添加到路径

<a href= "/Initial_Report"> Send Initial Report</a>
© www.soinside.com 2019 - 2024. All rights reserved.