0

I have a simple blog app that has a blog home and the details. I am using slug for detail URLs and prepopulating the slug field with the post title. everything works fine local but after I deployed the app online, when I click the post to go to its' blog detail it won't find the page.

this is my post models:

class PostManager(models.Manager):
    def get_queryset(self):
        return PostQuerySet(self.model, using=self._db)

    def search(self, query=None):
        return self.get_queryset().search(query=query)

class Post(models.Model):
    objects = PostManager()
    title = models.CharField(max_length=150)
    paragraph = models.TextField(blank=True)
    published = jmodels.jDateField()
    tags = TaggableManager()
    slug = models.SlugField(max_length=200, unique=True, allow_unicode=True)

    def save(self, *args, **kwargs):
        self.slug = slugify(self.title)
        super(Post, self).save(*args, **kwargs)

this is my urls:

path('maghaalaat/', views.MaghaleMain.as_view(), name="blog-page"),
path('maghaalaat/tags/<slug:tag_slug>/', views.MaghaleTags.as_view(), name="tagged"),
re_path(r'maghaalaat/(?P<the_slug>[-\w]+)/', views.MaghaleDetail.as_view(), name='post-detail'),

this is my views:

class MaghaleMain(ListView):
    model = MaghaalaatPost
    template_name = 'Blog/Blog-elmi.html'
    queryset = MaghaalaatPost.objects.all()
    context_object_name = 'posts'
    ordering = ['-published']
    paginate_by = 3

    def get_context_data(self, **kwargs):
        context = super(MaghaleMain, self).get_context_data(**kwargs)
        context['tags'] = MaghaalaatPost.tags.all()
        return context


class MaghaleTags(ListView):
    model = MaghaalaatPost
    template_name = 'Blog/Blog-elmi.html'
    context_object_name = 'posts'

    def get_queryset(self):
        return MaghaalaatPost.objects.filter(tags__slug=self.kwargs.get('tag_slug'))

    def get_context_data(self, **kwargs):
        context = super(MaghaleTags, self).get_context_data(**kwargs)
        context['tags'] = MaghaalaatPost.tags.all()
        return context


class MaghaleDetail(DetailView):
    model = MaghaalaatPost
    template_name = 'Blog/Blog-elmi-detail.html'
    context_object_name = 'maghaale'
    slug_url_kwarg = 'the_slug'
    slug_field = 'slug'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context["related_items"] = self.object.tags.similar_objects()[:3]
        return context

this is the error I get(I changed the debug to true in order to see the errors): enter image description here

please help me I don't know what am I doing wrong and why I only have this issue online

Sam
  • 379
  • 2
  • 10
  • The characters which make up your slug aren't valid for a URL. You can get details on valid characters here; https://stackoverflow.com/a/7109208/1199464 – markwalker_ Jul 04 '21 at 22:33
  • Its in persian. how do i validate that? – Sam Jul 06 '21 at 06:43
  • yeah, persian characters aren't valid for a URL. You'll need something that will convert non-ascii characters so that they can be used in a URL. – markwalker_ Jul 06 '21 at 10:48

0 Answers0