[英]How to send variables from one views to another?
in my html template I have a variable {{ student.mail}}
from context in view Nr.1.在我的 html 模板中,我在视图 Nr.1 中有一个来自上下文的变量
{{ student.mail}}
。 In this template I also have button <a class="btn btn-warning" href="{% url 'send_and_home' mail=student.mail %}" role="button">Save and Send</a>
.在这个模板中,我还有按钮
<a class="btn btn-warning" href="{% url 'send_and_home' mail=student.mail %}" role="button">Save and Send</a>
。 How to send this student.mail to the view Nr.2.如何将这个 student.mail 发送到视图 Nr.2。 The first view returns home page without any.
第一个视图返回没有任何主页。 My second page also returns the same home page, but also inside have an additional function to send mail.
我的第二页也返回同样的主页,而且里面还有一个额外的function发送邮件。 I don't understand how to implement something like this?
我不明白如何实施这样的事情? Could you help me?
你可以帮帮我吗?
my urls:我的网址:
path('home/', views.home, name="home"),
my 1st view:我的第一个观点:
@login_required(login_url='login')
def home(request):
# smth
context = ...
return render(request, 'app/home.html', context)
my 2nd view:我的第二个观点:
@login_required(login_url='login')
def send_and_home(request, mail):
# article, text, to for mail() depends on mail var from my template
mail()
context = the same as a view Nr.1
return render(request, 'app/home.html', context)
def mail(request, article, text, to):
return send_mail(
article,
'text',
'........',
[to,],
fail_silently=False,
)
Ok, I am just add new tag:好的,我只是添加新标签:
import re
from django import template
from django.core.mail import send_mail
register = template.Library()
@register.filter
def mail(address):
return send_mail(
'....',
'Test 2) ',
'.....',
[address,],
fail_silently=False,
)
And then in template:然后在模板中:
{% load mail %}
....
{{ var | mail }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.