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

Alexander Birch
Alexander Birch
1,804 Points

url name edit_quiz takes me to the course_detail.html template rather than the quiz_form.html template

Hi, Sorry if im asking the question incorrectly, its my first issue.

So im having some problems when I try to redirect the user to edit the quiz, on the quiz detail page it takes me to the course detail page. Im on this video, https://teamtreehouse.com/library/django-forms/model-forms/edit-an-instance

Views.py

@login_required def quiz_edit(request, course_pk, quiz_pk): quiz = get_object_or_404(models.Quiz, pk=quiz_pk, course_id=course_pk) form = forms.QuizForm(instance=quiz) return render(request, 'courses/quiz_form.html', {'form':form, 'course':quiz.course})


urlpatterns = [ url(r'^$', views.course_list, name='course_list'), url(r'(?P<course_pk>\d+)/t(?P<step_pk>\d+)/$', views.text_detail, name='text_detail'), url(r'(?P<course_pk>\d+)/q(?P<step_pk>\d+)/$', views.quiz_detail, name='quiz_detail'), url(r'(?P<course_pk>\d+)/create_quiz/$', views.quiz_create, name='create_quiz'), url(r'(?P<pk>\d+)/$', views.course_detail, name='course_detail'), url(r'(?P<course_pk>\d+)/edit_quiz/(?P<quiz_pk>\d+)/$', views.quiz_edit, name='edit_quiz'), ]


quiz_detail

{% block content %} <div class="row columns"> <article> {{ block.super }} <h1>{{ step.title }}</h1> Quiz questions here </article> {% if user.is_authenticated %} <hr /> <a href="{% url 'courses:edit_quiz' course_pk=step.course.pk quiz_pk=step.pk %}" class="button">Edit the Quiz</a> {% endif %} {% endblock %}