如何为具有slug的网址生成本地化?

时间:2021-07-13 16:36:34

I have a Django 1.7 project and I have been able to generate localised urls using the following format -

我有一个Django 1.7项目,我已经能够使用以下格式生成本地化的URL -

from django.utils.translation import ugettext_lazy as _

url(_(r'^about-us/$'), 'aboutus', name='aboutus'),

My problem is that I have following urls -

我的问题是我有以下网址 -

url(_(r'^products/$'), 'products_list', name='products'),
url(r'^products/(?P<slug>[-\w]+)/$', 'products_list', name='products_category'),

I am generating language based slug using modeltranslation package. But, I am unable to generate local url using this format -

我正在使用modeltranslation包生成基于语言的slug。但是,我无法使用此格式生成本地网址 -

url(_(r'^products') + '/(?P<slug>[-\w]+)/$', 'products_list', name='products_category'),

So, what is happening is that say for German I have 'produkte; and a product name soap slug is 'seife'. So, instead of /produkte/seife, I am getting /products/seife. How can I generate /produkte/seife?

所以,正在发生的事情就是德语说我有'produkte;产品名称soap slug是'seife'。所以,而不是/ produkte / seife,我得到/产品/ seife。我该如何生成/ produkte / seife?

Thanks

1 个解决方案

#1


0  

You should pass the whole URL regex (including the slug part) to ugettext_lazy (Translating URL patterns:

您应该将整个URL正则表达式(包括slug部分)传递给ugettext_lazy(翻译URL模式:

url(_(r'^products/(?P<slug>[\w-]+)/$'), 'products_list', name='products_category'),

#1


0  

You should pass the whole URL regex (including the slug part) to ugettext_lazy (Translating URL patterns:

您应该将整个URL正则表达式(包括slug部分)传递给ugettext_lazy(翻译URL模式:

url(_(r'^products/(?P<slug>[\w-]+)/$'), 'products_list', name='products_category'),