如何处理模板标记{%%}中的变量,我需要为函数send_mail_view()提供参数

urls.py

urlpatterns = [
path('send_mail_view/<sender_email>/<receiver_email>/<doc>',views.send_mail_view, name='send_mail_view'),


]

mailing_app / views.py

def send_mail_view(request,sender_email,receiver_email,doc):
    email=EmailMessage( 'i want to hire you Nitish ', 'please provide your resume', sender_email, [receiver_email] )
    email.attach_file('mailing_app/179.pdf')
    res=email.send(fail_silently=False)
    success_msg="mail sent success fully"
    return render(request,'mailing_app/success.html',{'success_msg':success_msg})


student_app / views.py

def student_main_view(request,username):
user_obj=User.objects.filter(username=username)
pdf_student_model_obj=pdf_student_model.objects.filter(username__in=user_obj)
pdf_list=[]
for p in pdf_student_model_obj:
    print("nikseva",type(p.pdf_id))
    pdf_indexing_model_obj=pdf_indexing_model.objects.filter(pdf_id=str(p.pdf_id))
    for x in pdf_indexing_model_obj:
        pdf_list.append({'pdf_id':x.pdf_id,'pdf_title':x.pdf_title,'pdf_abstract':x.pdf_abstract,'pdf_path':x.pdf_path,'sender_email':"[email protected]",'receiver_email':username,})

print("pdf_list",pdf_list)
return render(request,'rnd_app/student_mainpage.html',{'pdf_list':pdf_list})


templates / mail.html

{% for z in pdf_list %}
  pdf_title :{{z.pdf_title}}
  pdf_abstract:{{z.pdf_abstract}}<br>
  pdf_path:{{z.pdf_path}}
  <a href="{% url 'mailing_app:send_mail_view' {{request.user.username}} {{z.receiver_email}} {{z.pdf_path}} %}" class="btn1 ">Send Email</a>
{% endfor %}

最佳答案

当您已经在模板标签中时,就不需要变量花括号了。只需直接引用它们:

{% url 'mailing_app:send_mail_view' request.user.username z.receiver_email z.pdf_path %}

10-08 05:06