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 Django Basics Test Time Django TDD

TDD: can't pass final challenge

Just having trouble with the final challenge. Also, to complicate things I can't get the command 'python manage.py tests' to run the unit tests in workspaces. So I have no idea which test is failing, haha!

songs/models.py
from django.db import models

# Write your models here

class Song(models.Model):
  title = models.CharField(max_length=255)
  artist = models.CharField(max_length=255)
  performer = models.ForeignKey("Performer")
  length = models.IntegerField(default=0)

  def __str__(self):
    return self.title + "by" + self.artist


class Performer(models.Model):
  name = models.CharField(max_length=255)

  def __str__(self):
    return self.name
songs/views.py
from django.shortcuts import get_object_or_404, render

from .models import Performer, Song

def song_list(request):
    songs = Song.objects.all()
    return render(request, 'songs/song_list.html', {'songs' : songs})

def song_detail(request, pk):

    song = get_object_or_404(Song, pk=pk)
    return render(request, 'songs/song_detail.html', {'song' : song})

def performer_detail(request, pk):
    performer = get_object_or_404(Performer, pk=pk)
    return render(request, 'songs/performer_detail.html', {'performer' : performer})
songs/templates/songs/performer_detail.html
{% extends 'base.html' %}

{% block title %}{{ performer }}{% endblock %}

{% block content %}
<h2>{{ performer }}</h2>
  {% for song in performer.song_set.all %}
    <{{ song.title }}> by <{{ song.artist }}>
  {% endfor %}
{% endblock %}

3 Answers

There was a slight error in the html. Removing '<' and '>' from the line that prints the song.title and song.artist works.

{% extends 'base.html' %}

{% block title %}{{ performer }}{% endblock %}

{% block content %}
<h2>{{ performer }}</h2>
  {% for song in performer.song_set.all %}
    <{{ song.title }}> by <{{ song.artist }}> # line with the error
    {{ song.title }} by  {{ song.artist }}
  {% endfor %}
{% endblock %}
Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Sorry it can be frustrating! The command you seek is python manage.py test (not plural).

To run individual tests specify its name or to stop on first failure use the switch --failfast. Other test options can be listed using --help:

$ python manage.py test --help
usage: manage.py test [-h] [--version] [-v {0,1,2,3}] [--settings SETTINGS]
                      [--pythonpath PYTHONPATH] [--traceback] [--no-color]
                      [--noinput] [--failfast] [--testrunner TESTRUNNER]
                      [--liveserver LIVESERVER] [-t TOP_LEVEL] [-p PATTERN]
                      [-k] [-r] [-d]
                      [test_label [test_label ...]]

Discover and run tests in the specified modules or the current directory.

positional arguments:
  test_label            Module paths to test; can be modulename,
                        modulename.TestCase or modulename.TestCase.test_method

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -v {0,1,2,3}, --verbosity {0,1,2,3}
                        Verbosity level; 0=minimal output, 1=normal output,
                        2=verbose output, 3=very verbose output
  --settings SETTINGS   The Python path to a settings module, e.g.
                        "myproject.settings.main". If this isn't provided, the
                        DJANGO_SETTINGS_MODULE environment variable will be
                        used.
  --pythonpath PYTHONPATH
                        A directory to add to the Python path, e.g.
                        "/home/djangoprojects/myproject".
  --traceback           Raise on CommandError exceptions
  --no-color            Don't colorize the command output.
  --noinput             Tells Django to NOT prompt the user for input of any
                        kind.
  --failfast            Tells Django to stop running the test suite after
                        first failed test.
  --testrunner TESTRUNNER
                        Tells Django to use specified test runner class
                        instead of the one specified by the TEST_RUNNER
                        setting.
  --liveserver LIVESERVER
                        Overrides the default address where the live server
                        (used with LiveServerTestCase) is expected to run
                        from. The default value is localhost:8081.
  -t TOP_LEVEL, --top-level-directory TOP_LEVEL
                        Top level of project for unittest discovery.
  -p PATTERN, --pattern PATTERN
                        The test matching pattern. Defaults to test*.py.
  -k, --keepdb          Preserves the test DB between runs.
  -r, --reverse         Reverses test cases order.
  -d, --debug-sql       Prints logged SQL queries on failure.

Yeah, I figured out the test command but I get the following error: File "/usr/local/pyenv/versions/3.5.0/lib/python3.5/site-packages/django/db/backends/sqlite 3/base.py", line 323, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: songs_song

It seems the error is in the database or base.py file. I am using workspaces to complete the challenge so I don't think I can access either file. There may be more errors in the code but this one keeps failing the test command.