我是 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', 'from@example.com', noc_emails)cs_message = ('Initial Outage Report', 'This is a new outage report ,The information is in the document', 'from@example.com', 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' ),]首页.html<button> Send Initial Report</button>
1 回答
侃侃无极
TA贡献2051条经验 获得超10个赞
sinceInitial_Report
在触发 /Initial_Report 时调用
path('Initial_Report', views.Initial_Report, name = 'Initial_Report' ),
您可以添加一个链接到路径
<a href= "/Initial_Report"> Send Initial Report</a>
- 1 回答
- 0 关注
- 85 浏览
添加回答
举报
0/150
提交
取消