erfan
erfan

Reputation: 1

I have a problem with django-taggit persian[farsi-fa]

I have a problem when I put persian tags in the Django admin panel I get this error in template:

Reverse for 'post_tag' with arguments '('',)' not found. 1 pattern(s) tried: ['tags/(?P<tag_slug>[-a-zA-Z0-9_]+)/\\Z']

Note: when I put English and other languages tag I don't get this error and it works True.

models.py

from django.db import model
from taggit.managers import TaggableManager

class Article(models.Model):
    ...
    tags = TaggableManager()

views.py

from django.views.generic import ListView

class ArticleTagList(ListView):
    model = Article
    template_name = 'blog/list.html'

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

urls.py

from django.url import path
from .views import ArticleTagList

app_name = 'blog'
urlpatterns = [
    ...
    path("tags/<slug:tag_slug>/", ArticleTagList.as_view(), name='post_tag'),
    ...
]

blog/list.html

 ...
 
 {% for tag in article.tags.all %}
     <a href="{% url 'blog:post_tag' tag.slug %}">{{ tag.name }}</a>
 {% endfor %}

 ...

enter image description here

I change django-taggit version to last version bun not working. I'm now using 3.1.0 version. What can I do? Is there any solution for this problem?

Upvotes: 0

Views: 168

Answers (1)

Odyvia42
Odyvia42

Reputation: 13

I've ran into similar error while trying to work with cyrillic tags. The problem turned out to be not in django-taggit itself, but in the path converter. Just like you, I used slug in my urlpatterns, and it only worked with latin letters, giving me 'Reverse not found' error whenever I switched to cyrillic.

The problem here is, slug path converter only understands ASCII symbols, which only contains latin letters. I changed it to str path converter, 'tags/<str:tag_slug>', and it worked with cyrillic tags just fine, so maybe it'll work for you as well.

Upvotes: 1

Related Questions