0
I’m taking some Python lessons with Django and is making this mistake:
py.
from django.urls import path
from . import views
app_name = 'courses'
urlpatterns = [
path('', views.index, name='index'),
path('<str:slug>/', views.details, name='details'),
path('<str:slug>/anuncios/', views.announcements, name='announcements'),
path('<str:slug>/anuncios/<pk>', views.show_announcement, name='show_announcement'),
path('<str:slug>/inscricao/', views.enrollment, name='enrollment'),
path('<str:slug>/cancelar-inscricao/', views.undo_enrollment, name='undo_enrollment'),
path('<str:slug>/aulas/', views.lessons, name='lessons'),
path('<str:slug>/aulas/<pk>/', views.lesson, name='lesson'),
path('<str:slug>/materiais/<pk>/', views.material, name='material'),
]
py views.
@login_required
@enrollment_required
def announcements(request, slug):
course = request.course
template = 'courses/announcements.html'
context = {
'course': course,
'announcements': course.announcements.all(),
}
return render(request, template, context, slug)
@login_required
@enrollment_required
def show_announcement(request, slug, pk):
course = request.course
announcement = get_object_or_404(course.announcement.all(), pk=pk)
form = CommentForm(request.POST or None)
if form.is_valid():
comment = form.save(commit=False)
comment.user = request.user
comment.announcement = announcement
comment.save()
form = CommentForm()
messages.success(request, 'Seu comentário foi enviado com sucesso')
template = 'courses/show_announcement.html'
context = {
'course': course,
'announcement': announcement,
'form': form,
}
return render(request, template, context, pk, slug)
show_annoucement.html
{% extends "courses/course_dashboard.html" %}
{% block dashboard_content %}
{% for announcement in announcements %}
<div class="well">
<h2>
<a href="{% url 'courses:show_announcement' Course.slug
announcement.pk %}">{{ announcement.title }}</a>
</h2>
{{ announcement.content|linebreaks }}
<p>
<a href="{% url 'courses:show_announcement' Course.slug
announcement.pk %}#comments">
<i class="fa fa-comments-o" aria-hidden="true"></i>
{% with comments_count=announcement.comments.count %}
{{ comments_count }} Comentário{{ comments_count|pluralize
}}
{% endwith %}
</a>
</p>
</div>
{% empty %}
<div class="well">
<h2>Nenhum anúncio criado</h2>
</div>
{% endfor %}
{% endblock %}
course_dashboard.html
{% extends "accounts/dashboard.html" %}
{% block breadcrumb %}
{{ block.super }}
<li>/</li>
<li><a href="{% url 'courses:announcements' course.slug %}">{{ course }}
</a></li>
{% endblock %}
{% block menu_options %}
<li class="pure-menu-heading">
{{ course }}
</li>
<li>
<a href="{% url 'courses:lessons' course.slug %}">
<i class="fa fa-video-camera"></i>
Aulas e Materiais
</a>
</li>
<li>
<a href="#">
<i class="fa fa-info-circle"></i>
Informações
</a>
</li>
<li>
<a href="{% url 'courses:announcements' course.slug %}">
<i class="fa fa-envelope"></i>
Anúncios
</a>
Edit the question and add the template part
base.html
that is causing the error.– afonso
@drec4s there’s the base.html.
– Joice Santos
This part of the template has no URL for the show_annoucement view. I wanted to see was the part inside the
block content
view that causes the error.– afonso
@drec4s placed show_annnoucemnt.html and course_dashboard.html. I hope it’s one of those, because there are mitas inheritances in the templates.
– Joice Santos