Skip to content

Commit 954f36e

Browse files
committed
Implement save user input in result page
1 parent d17aa25 commit 954f36e

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

app/templates/home.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ <h1 class="title" style="text-align: center">Search Tutorials</h1>
3333
<form action="{% url 'app:search-results' %}" method="get" onsubmit="return checkEmpty()">
3434
<div class="field">
3535
<div class="control has-icons-left">
36-
<input class="input is-rounded" name="q" type="search" placeholder="search tutorials..." id="search-bar">
36+
<input class="input is-rounded" name="q" type="search" placeholder="search tutorials..." id="search-bar" value="{{ query }}">
3737
<span class="icon is-small is-left">
3838
<i class="fa fa-search" aria-hidden="true"></i>
3939
</span>
@@ -47,7 +47,11 @@ <h1 class="title" style="text-align: center">Search Tutorials</h1>
4747
<select name="category">
4848
<option disabled selected value="">Select Category</option>
4949
{% for category_value, category_name in categories %}
50-
<option value="{{ category_value }}">{{ category_name }}</option>
50+
<option value="{{ category_value }}"
51+
{% if category_value == category %} selected {% endif %}
52+
>
53+
{{ category_name }}
54+
</option>
5155
{% endfor %}
5256
</select>
5357
</div>
@@ -61,4 +65,4 @@ <h1 class="title" style="text-align: center">Search Tutorials</h1>
6165
</div>
6266
</section>
6367
{% block results %}{% endblock results %}
64-
{% endblock content %}
68+
{% endblock content %}

app/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def search_query(request):
5151

5252
context = {
5353
'query': query,
54+
'category': category,
5455
'tutorials': tutorials,
5556
'total': total,
5657
'time': result_time,

0 commit comments

Comments
 (0)