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 trialNIKOLAOS CHRISTOU
4,724 PointsError: Page not found (404)
Hi,
I receive this error Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/courses/1/
Using the URLconf defined in Basic_Django.urls, Django tried these URL patterns, in this order: ^courses/ ^$ [name='list'] ^courses/ ^(?P<course_pk>\d+)/(?P<step_pk>\d+)$ [name='step'] ^courses/ ^(?P<pk>\d+)$ [name='course_detail'] ^admin/ ^$ [name='hello_world'] ^static\/(?P<path>.*)$ The current path, courses/1/, didn't match any of these. You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
Can somebody help me?
2 Answers
Kurt Maurer
16,725 PointsI would verify your syntax in courses/templates/.
EDIT: Also, if you continue to have issues, if you could post your code wrapped in ```(tick marks to the left of 1 on the keyboard), that would help a lot! I'd probably need to see courses/views.py, and courses/urls.py, at a minimum.
course_detail.html
{% extends "layout.html" %}
{% block title %}{{ course.title }}{% endblock %}
{% block content %}
<article>
<h2>{{ course.title }}</h2>
{{ course.description }}
<section>
{% for step in course.step_set.all %}
<h3><a href="{% url 'courses:step' course_pk=step.course.pk step_pk=step.pk %}">{{ step.title }}</a></h3>
{{ step.description }}
{% endfor %}
</section>
</article>
{% endblock %}
course_list.html
{% extends "layout.html" %}
{% block title %}Available Courses{%endblock %}
{% block content %}
<div class="cards">
{% for course in courses %}
<div class="cards">
<header><a href="{% url 'courses:detail' pk=course.pk %}">{{ course.title }}</a></header>
<div class="card-copy">
{{ course.description }}
</div>
</div>
{% endfor %}
</div>
{% endblock %}
step_detail.html
{% extends "layout.html" %}
{% block title %}{{ step.title }} - {{ step.course.title }}{% endblock %}
{% block content %}
<article>
<h2><a href="{% url 'courses:detail' pk=step.course.pk %}">{{ step.course.title }}</a></h2>
<h3>{{ step.title }}</h3>
{{ step.content|linebreaks }}
</article>
{% endblock %}
NIKOLAOS CHRISTOU
4,724 PointsMr Mauer
Thank you very much for the interest you showed. I had written 2 times the same thing: {{ step.description }}
Thanks
NIKOLAOS CHRISTOU
4,724 PointsThanks for your answer.
Now they give me this error:
NoReverseMatch at /courses/1/
Reverse for 'step' with keyword arguments '{'course_pk': '', 'step_pk': 2}' not found. 1 pattern(s) tried: ['courses/(?P<course_pk>\d+)/(?P<step_pk>\d+)/$']
Request Method: GET
Request URL: http://127.0.0.1:8000/courses/1/
Django Version: 1.11
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'step' with keyword arguments '{'course_pk': '', 'step_pk': 2}' not found. 1 pattern(s) tried: ['courses/(?P<course_pk>\d+)/(?P<step_pk>\d+)/$']
Kurt Maurer
16,725 PointsKurt Maurer
16,725 PointsHey Nikolaos,
I'm assuming that the error is coming from naming or syntax somewhere in urls.py or views.py. Without being able to see your code directly, I'll post what worked for me in this exercise, and you can compare from there. I'll continue to look around in the meantime.
First, check that you're making all of the correct imports.
EDIT: My guess is that there's an issue with your primary key(pk) in views.py. If you determine the solution on your own, let me know!
courses/urls.py
courses/views.py