猿问

Django 如何分配从 HTML 按钮发送电子邮件的功能

我是 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>


眼眸繁星
浏览 86回答 1
1回答

侃侃无极

sinceInitial_Report在触发 /Initial_Report 时调用path('Initial_Report',&nbsp;views.Initial_Report,&nbsp;name&nbsp;=&nbsp;'Initial_Report'&nbsp;),您可以添加一个链接到路径<a&nbsp;href=&nbsp;"/Initial_Report">&nbsp;Send&nbsp;Initial&nbsp;Report</a>
随时随地看视频慕课网APP

相关分类

Html5
我要回答