Search code examples
htmlformsinheritancedjango-formsradix

How can I solve this error in my html search template?


So I'm trying to develop an app in Django. At the moment I'm trying to do a simple search bar that when you type the title of a fil it show several data of that film. I have successfully developed the search bar and it works. The problem is that when doing the html template and extending it from base.html the data shown dissapears.

base.html

<!DOCTYPE html>
    <html lang="es">
    <head>
      {% load staticfiles %}

    <title>Peliculas</title>
    <meta name="description" content="website description" />
    <meta name="keywords" content="website keywords, website keywords" />
    <meta http-equiv="content-type" content="text/html; charset=windows-1252" />
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
    <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css? 
    family=Tangerine&amp;v1" />
    <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css? 
    family=Yanone+Kaffeesatz" />
    <link rel="stylesheet" type="text/css" href="{% static 'myapp/style.css' %}"/>  
    </head>
    <body>
        <div id="content">

		 
		   <div id="main">
    <div id="header">
      <div id="logo">
        <h1>SERIAL KILLER</h1>
        <div class="slogan">SLOGAN</div>
      </div>
      <div id="menubar">
        <ul id="menu">
          <!-- put class="current" in the li tag for the selected page - to highlight which page you're 
          on -->
		  {%block menu%}
			
		  {% endblock %}
          
        </ul>
      </div>
    </div>
    </div>
		 
		 <div id="site_content">
			{%block lado%}
			
			
			{% endblock %}
			<div id="content">
         
        {% block contenido %}
			{% endblock %}
        </div>
		
		
    </body>
</html>

the template where I show the data from the query: buscarResultados.html

{% extends "base.html" %}
    {% load staticfiles %}
    {% block titulo %} RESULTADOS {% endblock %}
    {%block content %}
    
        <ul>
            {% for peli in object_list %}
            <li>
                {{peli.titulo}}, {{peli.descripcion}}
            </li>
            {% endfor %}
        </ul>
    
    {% endblock %}

my form in index.html

<div id="search">
				<form action="{% url 'busqueda_resultados' %}" method= 'get'>
					<input type="text" name="q" placeholder="Buscar...">
					<input type="submit" value="Buscar">
				</form>
			</div>

my views.py

class BuscarPeliculas(ListView):
model = Pelicula
template_name = 'buscarResultados.html'

def get_queryset(self):
    query = self.request.GET.get('q')
    object_list = Pelicula.objects.filter(
        Q(titulo__icontains=query) | Q(descripcion__icontains=query)
    )
    return object_list

my urls.py

path('busqueda/', views.BuscarPeliculas.as_view(), name='busqueda_resultados'),

what appears if I extend from base.html

enter image description here

What appears if I don't extend from base.html enter image description here

as you can see, The data dissapears if I extend from base.html, I tried to do my question as complete as possible, help is much appreciated.


Solution

  • Its because you are addintg it to a block content, but the base.html expects block contenido

    fix your block names