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

Keifer Joedicker
Keifer Joedicker
5,869 Points

Still working on fully grasping Django, not sure why this isn't passing? Explanations appreciated

Copy and paste your models, views, and performer template from Workspaces into the correct files below.

songs/models.py
class Song(Models.model):
  title = models.TextField()
  artist = models.TextField()
  performer = Performer.name
  length = models.DurationField()
   def __str__(self):
      return (f"{self.title} by {self.artist}")

class Performer(Models.model):
  name = models.TextField()
  def __str__(self):
    return self.name
songs/views.py
from django.shortcuts import get_object_404, render

from .models import Song, Performer

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


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

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

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

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

2 Answers

Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

Hi Keifer, First, models.py: It's missing the models import from django.db. The classes inherit from Models.model which it should be models.Model. The first class attributes relative with the str function, they are not in the same column, indentetion issue, for best practise i recomend to use 4 spaces in python for better visual. Second, views.py: the functions should return the rendered template, not just render, it is missing the 'return' . Also i would add, i recomend to use .format() function instead of f" " because that is just in python 3.6 and above, in the future you can have problem with this if you use different version of python. I hope this helps you out. If you have more issues or any question don't hasitate to ask. Happy coding

Keifer Joedicker
Keifer Joedicker
5,869 Points

Thank for your feedback.

I went through after I had posted and noticed a few syntax errors I had overlooked. I'll make the adjustments you recommended as well and try again.