我是 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' ),]首頁.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 關注
- 157 瀏覽
添加回答
舉報
0/150
提交
取消