Hi Raja Sekar Sambath
I tried what you said and didn't run well. I don't know why is not running
with reverse function.
I managed do what I wanted. I did this:
def get_absolute_url(self):
return '%s' % self.slug
Thanks & Regards,
Bruno Gama
+55 12 9 9171-6336.
Le ven. 24 avr. 2020 à 11:50, Raja Sekar Sambath <[email protected]> a
écrit :
> 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 <[email protected]> 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 <[email protected]> a
>> écrit :
>>
>>> decorating get_absolute_url with @staticmethod may help I think
>>>
>>> On Fri, 24 Apr 2020 at 00:35, Bruno Gama <[email protected]> wrote:
>>>
>>>> I tried it, but happens the same error.
>>>>
>>>> Le jeu. 23 avr. 2020 à 13:54, Jorge Gimeno <[email protected]> a
>>>> écrit :
>>>>
>>>>>
>>>>>
>>>>> 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
>>>>> <https://groups.google.com/d/msgid/django-users/CANfN%3DK9zqMGm5hxVMSQsNfS%2ByBKyuMLayv0ARK6ofuT9hg2%2BSg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>> --
>>>> 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/CAOTVoPANyFBchm-gK28YRJ_TtNaT3p%3DOHoUZco6Wzu2PKybs8A%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/django-users/CAOTVoPANyFBchm-gK28YRJ_TtNaT3p%3DOHoUZco6Wzu2PKybs8A%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>
>>>
>>> --
>>> 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 [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAAS5AE5ZD_LetM2Z3oEaXq8MyALDBMYAsxW3yDk66r%2B2PyfypQ%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAAS5AE5ZD_LetM2Z3oEaXq8MyALDBMYAsxW3yDk66r%2B2PyfypQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>
>> 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 [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAOTVoPAv1HJr_HOQuDCoWtsv-Mo6L6Fc6jBqaO29-eeTk86XBQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAOTVoPAv1HJr_HOQuDCoWtsv-Mo6L6Fc6jBqaO29-eeTk86XBQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> --
> 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 [email protected].
> 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
> <https://groups.google.com/d/msgid/django-users/CAAS5AE5p%2BRkZB-2%3DhyPesGvu-f_8pAURbmPy5QfxF3DwGPRoEw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
--
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/CAOTVoPDJixt%3D23g3mQG1kAuOBbdYEZZzmvJz8eANL9%2BwDqucVw%40mail.gmail.com.