Hi, Folks. I hope the week is treating you all well.
I’m a bit confused on why something isn’t working and was hoping for some feedback.
The setup is thus:
I’ve got a base.html file and a blocks.html file. blocks.html obviously extends base.html.
I also have a results.html file.
As of right now, while I experiment around, both results.html and blocks.html have the exact same content. The both define all blocks for base.html exactly the same EXCEPT for one block - {% block front %}
.
in blocks.html it looks like this →
{% block front %}
<div class="row align-items-start py-5">
{% for i in range %}
<div class="col-4">
<div class="card">
<video controls>
<source src="" type="video/mp4">
</video>
<div class="card-body text-center">
<h3 class="card-title h5"><a href="article.html">Livestreaming</a></h3>
<div class="card-text">
Someone Livestreaming something from somewhere at sometime with someone involved
</div>
</div>
</div>
</div>
{% endfor %}
</div>
{% endblock front %}
in results.html it looks like this →
{% block front %}
<div class="row align-items-start py-5">
<div class="col">
<h4>Mainstream Results: </h4>
</div>
<div class="col">
<h4>Fringe Results: </h4>
</div>
</div>
<!-- loop block -->
<div class="row align-items-start py-2">
<div class="col">
<h5>Searched version: {{ search_string }}</h5>
</div>
<div class="col">
<h5>Opposing version: {{ fringe_string }}</h5>
</div>
</div>
{% endblock front %}
my views.py is this →
def index(request):
template = 'searchnet/blocks.html'
context = {
"location": location,
"weather": weather,
"icon": icon,
"menu": [
.........
],
"range": range(3),
}
return render(request, template, context)
def results(request, search_string):
template = 'searchnet/results.html'
context = {
"search_string": search_string,
"fringe_string": search_string[::-1]
}
return render(request, template, context)
And my urls.py is this →
urlpatterns = [
path('', views.index, name='index'),
path('search/<str:search_string>/', views.results, name='results'),
]
The search bar is a block that looks like this →
{% block search %}
<form class="col-12 col-lg-auto mb-3 mb-lg-0 me-lg-3">
<input type="search" name="search" method="GET" class="form-control" placeholder="Search.. Anything, Anytime, Anyone, Anywhere, Anyhow" aria-label="Search">
</form>
{% endblock search %}
My confusion is that if I type something into the search bar the url changes to display the search term but results.html isn’t rendered. It stays on blocks.html; but like I said, the url bar reflects the change just the templates don’t change.
Can someone breakdown what’s happening here? I feel inside I’m missing a small link in the chain but I can’t put my finger on it. Thanks to all replies