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!

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 Final Details Content Field

ThatOneCoder -
ThatOneCoder -
9,310 Points

Problem with the website!

So I made everything work but the content showed something else, so i fixed that but it showed the how to use strings instead, it really was a easy fix, i just had to order it as 0. But at the time I thought that deleting it was a much better idea. so when that happend I could no longer go into python basics. and see the things. Here is my code.


from django.db import models

class Course(models.Model): created_at = models.DateTimeField(auto_now_add=True) title = models.CharField(max_length=255) description = models.TextField()

def __str__(self):
    return self.title

class Step(models.Model): title = models.CharField(max_length=255) description = models.TextField() content = models.TextField(blank=True, default='') order = models.IntegerField(default=0) course = models.ForeignKey(Course)

class Meta:
    ordering = ['order',]

def __str__(self):
    return self.title


{% extends "layout.html" %}

{% block title %}{{ step.title }} - {{ step.course.title }}{% endblock %}

{% block content %} <article> <h2>{{ step.course.title }}</h2> <h3>{{ step.title }}</h3> {{ step.content|linebreaks }} </article>

{% endblock %}


from django.shortcuts import get_object_or_404, render

from .models import Course, Step

def course_list(request): courses = Course.objects.all() return render(request, 'courses/course_list.html', {'courses': courses})

def course_detail(request, pk): course = get_object_or_404(Course, pk=pk) return render(request, 'courses/course_detail.html', {'course': course})

def step_detail(request, course_pk, step_pk): step = get_object_or_404(Step, course_id=course_pk, pk=step_pk)

return render(request, 'courses/step_detail.html', {'step': step})


{% extends "layout.html" %}

{% block title %}{{ course.title }}{% endblock %}

{% block content %} <article> <h2>{{ course.title }}</h2> {{ course.description }}

    {% for step in course.step_set.all %}
        <h3>{{ step.title }}</h3>
        {{ step.description }}
    {% endfor %}


{% endblock %}

Sorry if what I wrote here looks weird I don't know how to use this!

If anything is unclear just ask me!