Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['music\\/(?P<pk>[0-9]+)$']

I got a error like this could anyone help me

Hi Siva! I'd love to help, but I really can't without your code. Would you mind including it? Thanks :)

1 Answer

Models.py file

from django.db import models from django.urls import reverse

Create your models here.

class Albums(models.Model): artist = models.CharField(max_length = 100) album_title = models.CharField(max_length = 200) genre = models.CharField(max_length = 250) album_logo = models.CharField(max_length = 250)

def get_absolute_url(self):
    return reverse('musicapp:detail', kwargs={'pk': self.pk})

def __str__(self):
    return self.album_title + ' - ' + self.artist

class Song(models.Model): album = models.ForeignKey(Albums, on_delete = models.CASCADE) file_type = models.CharField(max_length = 10) song_title = models.CharField(max_length = 200) is_favorite = models.BooleanField(default= False)

def __str__(self):
    return self.song_title

urls.py

from django.contrib import admin from django.urls import path from django.conf.urls import url from. import views

app_name = "musicapp"

urlpatterns = [ path('', views.IndexView.as_view(), name = 'index'),

path('<int:pk>', views.DetailView.as_view(), name = 'detail'),

default.html

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>{% block title %}MYMUSIC{% endblock %}</title>

{% load staticfiles %}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link href='https://fonts.googleapis.com/css?family=Satisfy' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="{% static 'musicapp/style.css' %}"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

</head> <body> <nav class="navbar navbar-inverse navbar-fixed-top"> <div class="container-fluid">

        <!---HEADER-->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class=" navbar-brand" href="{% url 'musicapp:index' %}">Mymusic</a>
        </div>
        <!---ITEMS-->
        <div class="collapse navbar-collapse" id="#topNavBar">
            <ul class="nav navbar-nav">
                <li class="">
                    <a href="{% url 'musicapp:index' %}">
                        <span class="glyphicon glyphicon-cd" aria-hidden="true"></span> Albums
                    </a>
                </li>
                <li class="">
                    <a href="#">
                        <span class="glyphicon glyphicon-music" aria-hidden="true"></span> Songs
                    </a>
                </li>
            </ul>

            <form class="navbar-form navbar-left" role="search" method="get" action="#">
                <div class="form-froup">
                    <input type="text" class="form-control " name="q" value="">
                    <button type="submit" class="btn btn-default">Search</button>
                </div>
            </form>

            <ul class="nav navbar-nav navbar-right">
                <li class="">
                    <a href="{% url 'musicapp:add-album' %}">
                        <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add Albums
                    </a>
                </li>
                <li class="">
                    <a href="#">
                        <span class="glyphicon glyphicon-off" aria-hidden="true"></span> Logout
                    </a>
                </li>
            </ul>

        </div>

    </div>
</nav>

{% block body %}

index.html

{% extends 'musicapp/default.html' %} {% block body %}

<div class="albums-container container-fluid">

<!-- Albums-->
<div class="row">
    <div class="col-sm-12">
        <h2>'s Albums</h2>
    </div>
</div>

{% if all_albums %}
    {% for album in all_albums %}
        <div class="col-sm-4 col-lg-2">
            <div class="thumbnail">
                <a href="{% url 'musicapp:detail' album.id %}">
                    <img class="img-responsive" src="{{ album.album_logo}}">
                </a>
                <div class="caption text-left">
                    <h2 class="text-muted">{{album.album_title}}</h2>
                    <h2 class="text-muted ">{{album.artist}}</h2>

                    <!-- Details-->
                    <a href="{% url 'musicapp:detail' album.id %}" class="btn btn-primary btn-sm" role="button">View Details</a>

                    <!-- Delete Album-->
                    <form action="#" method="post" style=" display : inline">
                        {% csrf_token %}
                        <input type="hidden" name="album.id" value="{{ album.id }}" />
                        <button type="submit" class="btn btn-danger btn-sm">
                            <span class="glyphicon glyphicon-trash"></span>
                        </button>
                    </form>

                    <!-- Favorite Album -->
                    <a href="#" class="btn btn-default btn-sm btn-favorite">
                        <span class="glyphicon glyphicon-star {% if album.is_favorite %} active {% endif %}"></span>
                    </a>

                </div>
            </div>
        </div>


    {% endfor %}
{% else %}
    <div class="col-sm-12">
         <br>
        <a href="#">
            <button type="button" class="btn btn-success">
               <span class="glyphicon glyphicon-plus"></span> &nbsp; Add an Album
           </button>
        </a>

    </div>
{% endif %}

</div>

<!-- Search --> {% if songs %} <div class="row"> <div class="col-sm-12"> <h3>Songs</h3> </div> <div class="col-sm-12"> <div class="panel panel-default"> <div class="panel-body"> <table class="table"> <thead> <tr> <th>Song tilte</th> <th>Artist</th> <th>Audio File</th> <th>Album</th> <th>Favorite</th> </tr> </thead> <tbody> {% for song in songs %} <tr> <td>{{ song.song_title}}</td> <td>{{ song.album_title}}</td> <td> <a target="blank" href=""> <button type="button" class="btn btn-success btn-xs"> <span class="glyphicon glyphicon-play"></span>  Play </button> </a> </td> <td> <a href="{% url 'musicapp:detail' song.album.id %}"> <img src="{{ song.album.album_logo }}" class="img-responsive" style="width: 20px; float: left; margin-right: 10px;" /> </a> <a href="{% url 'musicapp:detail' song.album.id %}">{{ song.album.album_title }}</a> </td> <td> <a href="{% url 'musicapp:favorite' song.id %}" class="btn-favorite"><span class="glyphicon glyphicon-star {% if song.is_favorite %}active{% endif %}"></span></a> </td> </tr> {% endfor %} </tbody> </table> </div> </div> </div> </div> {% endif %} {% endblock %}


detail.html

{% extends 'musicapp/default.html' %}

<!--{% block title %}{{album.album_title}} Album by {{album.artist}} details{% endblock %}--> {% block albums_active %}active{% endblock %} {% block body %}

<div class="container-fluid songs-container"> <div class="row">

    <!--Album info-->
    <div class="col-sm-4 col-md-3">
        <div class="panel panel-default">
            <div class="panel-body">
                <a href="{% url 'musicapp:detail' album.id %}">
                    {% if album.album_logo %}
                        <img src="{{album.album_logo}}" class="img-responsive">
                    {% else %}
                        <h2>No image to display</h2>
                    {% endif %}
                </a>
                <h1>{{album.album_title}} <small>{{album.genre}}</small></h1>
                <h2>{{ album.artist }}</h2>
            </div>
        </div>
    </div>

    <!-- Song info-->
    <div class="col-sm-8 col-md-9">

        <ul class="nav nav-pills" style="margin-bottom : 10px">
            <li role="presentation" class="active"><a href="{% url 'musicapp:detail' album.id %}">View all</a> </li>
            <li role="presentation"><a href="#">Add New Song</a> </li>
        </ul>
        <div class="panel panel-default">
            <div class="panel-body">
                <h3> All Songs</h3>
                {% if error_message %}
                    <p><strong>{{ error_message }}</strong></p>
                {% endif %}
                <table class="table">
                    <thead>
                    <tr>
                        <th>Title</th>
                        <th>Audio File</th>
                        <th>Favorite</th>
                        <th>Actions</th>
                    </tr>
                    </thead>

                    <tbody>
                     {% for song in album.song_set.all %}
                        <tr>
                            <td>{{ song.song_title }}</td>
                            <td>
                                <a target="_blank" href="{{ song.audio_file.url }}">
                                    <button type="button" class="btn btn-success btn-xs">
                                        <span class="glyphicon glyphicon-play"></span>&nbsp; Play
                                    </button>
                                </a>
                            </td>
                            <td>
                                <a href="#" class="btn-favorite"><span class="glyphicon glyphicon-star {% if song.is_favorite %}active{% endif %}"></span></a>
                            </td>
                            <td>
                                <form action="#" method="post" style="display: inline;">
                                    {% csrf_token %}
                                    <input type="hidden" name="song_id" value="{{ song.id }}" />
                                    <button type="submit" class="btn btn-danger btn-xs">
                                        <span class="glyphicon glyphicon-remove"></span>&nbsp; Delete
                                    </button>
                                </form>
                            </td>
                        </tr>
                     {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

</div> {% endblock %}

Thank you for including your code Siva. :) I wish I could help. But unfortunately, I didn't realize your question was about Django. I haven't learned Django. :( Sorry.