admin管理员组

文章数量:1300018

I have troubles to translate properly a route that needs a param. this works fine if the uri has /fr/ or /en/:

urlpatterns = [
    path(_('CATEGORY'), views.category, name='app-category'),
]

But as long as I need to add a param like:

urlpatterns = [
    path(f"{_('CATEGORY')}/<slug:uuid>", views.category, name='app-category'),
]

or

urlpatterns = [
    path(_('CATEGORY') + "/<slug:uuid>", views.category, name='app-category'),
]

The translation stuck with 'category' so the route /fr/categorie/ is not working. _('CATEGORY') = 'categorie' for fr or 'category' for en.

Any idea about how to bypass the issue? Thanks

I have troubles to translate properly a route that needs a param. this works fine if the uri has /fr/ or /en/:

urlpatterns = [
    path(_('CATEGORY'), views.category, name='app-category'),
]

But as long as I need to add a param like:

urlpatterns = [
    path(f"{_('CATEGORY')}/<slug:uuid>", views.category, name='app-category'),
]

or

urlpatterns = [
    path(_('CATEGORY') + "/<slug:uuid>", views.category, name='app-category'),
]

The translation stuck with 'category' so the route /fr/categorie/ is not working. _('CATEGORY') = 'categorie' for fr or 'category' for en.

Any idea about how to bypass the issue? Thanks

Share Improve this question asked Feb 11 at 14:46 Sacha Rk.Sacha Rk. 211 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

I finally find a way just in case it can help others.

#views.py

category_patterns = (
    [
        path("/<slug:slug>/", views.category_detail, name='category-detail'),
    ],
    'category',
)

urlpatterns = [
    path(_('[CATEGORY/]'), include(category_patterns, namespace="category")),
]

本文标签: Django 5 translate route with paramStack Overflow