Friday, April 24, 2020

Re: django.urls.exceptions.NoReverseMatch: 'courses' is not a registered namespace

Hi Bruno Gama,
Try this, update 
reverse('courses:datails', (), {'slug': self.slug}) 
as
reverse('courses:datails', kwargs={'slug': self.slug})

On Fri, 24 Apr 2020 at 18:50, Bruno Gama <bqgama@gmail.com> wrote:
Thank you, Raja Sekar Sambath.

It stopped the error. I don't manage do what I want, but the error stopped running. 


Le ven. 24 avr. 2020 à 03:34, Raja Sekar Sambath <apkrajar@gmail.com> a écrit :
decorating get_absolute_url with @staticmethod may help  I think 

On Fri, 24 Apr 2020 at 00:35, Bruno Gama <bqgama@gmail.com> wrote:
I tried it, but happens the same error.

Le jeu. 23 avr. 2020 à 13:54, Jorge Gimeno <jlgimeno71@gmail.com> a écrit :


On Thu, Apr 23, 2020, 7:46 AM Bruno Gama <bqgama@gmail.com> 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 admin  from django.urls import path, include  from simplemooc.core import views, urls  from simplemooc.courses import views, urls  from django.conf import settings  from 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 path  from 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 models  from 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_404  from 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 django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANfN%3DK9zqMGm5hxVMSQsNfS%2ByBKyuMLayv0ARK6ofuT9hg2%2BSg%40mail.gmail.com.

--
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 django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOTVoPANyFBchm-gK28YRJ_TtNaT3p%3DOHoUZco6Wzu2PKybs8A%40mail.gmail.com.


--
Thanks & Regards,

Raja Sekar Sampath
+91 9087434567.

--
 
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 django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAAS5AE5ZD_LetM2Z3oEaXq8MyALDBMYAsxW3yDk66r%2B2PyfypQ%40mail.gmail.com.

Thanks & Regards,

Bruno Gama
+55 12 9 9171-6336. 

--
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 django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOTVoPAv1HJr_HOQuDCoWtsv-Mo6L6Fc6jBqaO29-eeTk86XBQ%40mail.gmail.com.


--
Thanks & Regards,

Raja Sekar Sambath
+91 90874 34567.

--
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 django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAAS5AE5p%2BRkZB-2%3DhyPesGvu-f_8pAURbmPy5QfxF3DwGPRoEw%40mail.gmail.com.

No comments:

Post a Comment