Browse Source

Se añade búsqueda de canciones

politica
Celestino Rey 1 year ago
parent
commit
1e7256fb35
4 changed files with 32 additions and 0 deletions
  1. +9
    -0
      LyricsPy/app.py
  2. BIN
      LyricsPy/instance/songs.db
  3. +4
    -0
      LyricsPy/templates/base.html
  4. +19
    -0
      LyricsPy/templates/search.html

+ 9
- 0
LyricsPy/app.py View File

@ -61,6 +61,15 @@ def album(album_id):
songs = Song.query.filter_by(album_id=album_id).all()
return render_template('album.html', album=album, songs=songs)
@app.route('/search')
def search():
query = request.args.get('query', '')
if query:
songs = Song.query.filter(Song.title.contains(query)).all()
else:
songs = []
return render_template('search.html', query=query, songs=songs)
if __name__ == '__main__':
with app.app_context():
db.create_all()


BIN
LyricsPy/instance/songs.db View File


+ 4
- 0
LyricsPy/templates/base.html View File

@ -12,6 +12,10 @@
<a href="{{ url_for('index') }}">Home</a>
<a href="{{ url_for('add_song') }}">Add Song</a>
<a href="{{ url_for('add_album') }}">Add Album</a>
<form action="{{ url_for('search') }}" method="get" style="display:inline;">
<input type="text" name="query" placeholder="Search songs...">
<button type="submit">Search</button>
</form>
</nav>
<hr>
{% block content %}{% endblock %}


+ 19
- 0
LyricsPy/templates/search.html View File

@ -0,0 +1,19 @@
{% extends 'base.html' %}
{% block content %}
<h2>Search Results for "{{ query }}"</h2>
{% if songs %}
<ul>
{% for song in songs %}
<li>
<a href="{{ url_for('song', song_id=song.id) }}">{{ song.title }} by {{ song.author }}</a>
</li>
{% endfor %}
</ul>
{% else %}
<p>No songs found matching your query.</p>
{% endif %}
<a href="{{ url_for('index') }}">Back to Home</a>
{% endblock %}

Loading…
Cancel
Save