我有一个工作站点,用户在其中将邮政编码输入表单,并显示与该邮政编码匹配的工作列表 search.html:
<h6>Results: {{ number_of_results }}</h6>
{% for job in jobs_matching_query %}
<h2><a class="job_link" href="#">{{ job.job_title}}</a></h2>
<p class="job_address lead">{{ job.establishment_name }} - {{ job.address }}</p>
{% endfor %}
<form action = "{% url 'email_subscription' %}">
<p>Subscribe to recieve job alerts near {{ query }}:</p> <!-- query stores zip code-->
<input type="text" name= "email" placeholder="Email">
<button class="btn" type="submit">Subscribe</button>
</form>
搜索表单由以下视图处理(不确定是否需要添加此视图):
def job_query(request):
if request.method == "GET":
query = request.GET.get('query')
jobs_matching_query = Job.objects.filter(zip_code__iexact = query) | Job.objects.filter(city__iexact=query) | Job.objects.filter(state__iexact=query)
number_of_results = 0
for job in jobs_matching_query:
number_of_results = number_of_results + 1
return render(request, 'core/search.html', {'query': query ,'jobs_matching_query': jobs_matching_query, 'number_of_results': number_of_results})
在该search.html上,我有一个电子邮件订阅框(订阅有关该特定邮政编码的警报),有没有一种方法可以将query
的值从该页面传递到email_subscription
视图?我相信我已经在网址中看到了这一点,所以这是上述视图的网址
url(r'^email_subscription$', views.email_subscription, name="email_subscription"),
答案 0 :(得分:0)
您可以使用Django会话,以便将查询保存在Django会话中
redirectUrl : chrome.extension.getURL("hello.html")
它可以工作,但是我不确定这是否是实用的