1👍
Change your template url tag to
{% url 'course_detail' course.id %}
and in your urls.py
url(r'^(?P<pk>[0-9]+)/course/$', views.course_detail, name='course_detail')
0👍
Firstly, you have assigned reverse name for courses detail url as Course_detail
in urls.py
but you are using the reverse name as course_detail
in your template. It should have been Course_detail
in the template.
Secondly, you are passing pk
as Course.pk
in your template. It should have been course.pk
instead as you are using course
variable when iterating over courses
objects.
Instead use reverse name with lowercase initial to remove the case-sensitive issues.
urls.py
from django.conf.urls import include, url
from Classes import views
from django.contrib import admin
admin.autodiscover()
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^$', views.classes_list, name='classes_list'),
url(r'^(?P<pk>[0-9]+)/Course/$', views.course_detail, name='course_detail'), # assign reverse name with lowercase initial letter
]
Then in your template, you can do this:
classes_list.html
{% extends "cacademy/base.html" %}
{% load staticfiles %}
{% block content %}
<div>
<h2> Remember you can only register 3 Courses at once!</h2>
</div>
{% for course in courses %}
<div course="post">
<div course="date">
{{ course.started_date }}
</div>
<h1><a href="{% url 'course_detail' pk=course.pk %}">{{ course.title }}</a></h1>
<p>Taught by: {{ course.teachername|linebreaks }}</p>
</div>
{% endfor %}
{% endblock content %}
- Django: How do I create a view to update multiple records on an intermediate model with a Many-to-Many-through relationship?
- Use variables in send_email()
- How to run(copy) django project from one system from another system?
- How to fetch SSL Certificate for django project in Azure?
- Django, reading csv from form request throws: Error: line contains NULL byte
Source:stackexchange.com