On Thu, Apr 23, 2020, 7:46 AM Bruno Gama <[email protected]> wrote:

> I have a problem since I tried to use get_absolute_url(self): to enter in
> a url beyond a photo. When I used , my index.html stopped running.
>
> Here I have the top level url.py
>
> from  import adminfrom django.urls import path, includefrom simplemooc.core 
> import views, urlsfrom simplemooc.courses import views, urlsfrom django.conf 
> import settingsfrom django.conf.urls.static import static
>
>
> urlpatterns = [path('admin/', admin.site.urls),
>                path('', include(('simplemooc.core.urls', 'simplemooc'), 
> namespace='core')),
>                path('cursos', include(('simplemooc.courses.urls', 
> 'simplemooc'), namespace='courses'))]
> if settings.DEBUG:
>     urlpatterns += static(settings.MEDIA_URL, 
> document_root=settings.MEDIA_ROOT)
>
> Here courses/url.py
>
> from django.urls import pathfrom simplemooc.courses import views
>
> urlpatterns = [path('', views.index, name='index'),
>                    path('/<slug:slug>/', views.details, name='datails')]
>
> Here courses/model.py
>
> from django.db import modelsfrom django.urls import reverse
>
> class CourseManager(models.Manager):
>
>     def search(self, query):
>         return self.get_queryset().filter(
>             models.Q(name__icontains=query) | \
>             models.Q(description__icontains=query)
>         )
>
> class Course(models.Model):
>
>     name = models.CharField('Nome', max_length=100)
>     slug = models.SlugField('Atalho')
>     description = models.TextField('Descrição Simples', blank=True)
>     about = models.TextField('Sobre o Curso', blank=True)
>     start_date = models.DateField(
>         'Data de Início', null=True, blank=True
>     )
>     image = models.ImageField(
>         upload_to='courses/images', verbose_name='Imagem',
>         null=True, blank=True
>     )
>
>     created_at = models.DateTimeField(
>         'Criado em', auto_now_add=True
>     )
>     updated_at = models.DateTimeField('Atualizado em', auto_now=True)
>
>     objects = CourseManager()
>
>     def __str__(self):
>         return self.name
>
>     def get_absolute_url(self):
>         return reverse('courses:datails', (), {'slug': self.slug})
>
>     class Meta:
>         verbose_name = 'Curso'
>         verbose_name_plural = 'Cursos'
>         ordering = ['name']
>
> And here courses/views.py
>
> from django.shortcuts import render, get_object_or_404from django.http import 
> HttpResponse
> from .models import Course
> <span class="kwd" style="font-style: inherit; font-variant: inherit; 
> font-weight: inherit; font-stretch: inherit; lin
>
> Bruno,

I believe it may be a typo in Course.get-absolute-url.  In the reverse
call, the first argument should be 'course:details".  In your code, it's
'course:datails'.

-Jorge

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANfN%3DK9zqMGm5hxVMSQsNfS%2ByBKyuMLayv0ARK6ofuT9hg2%2BSg%40mail.gmail.com.

Reply via email to