Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用Django中的波斯语或阿拉伯语从slug中反转Url_Python_Html_Django - Fatal编程技术网

Python 使用Django中的波斯语或阿拉伯语从slug中反转Url

Python 使用Django中的波斯语或阿拉伯语从slug中反转Url,python,html,django,Python,Html,Django,嗨,我想从slug中反转url 在模型中,我有slug: slug = models.SlugField(max_length=200, unique=True, allow_unicode=True) 对于获取绝对url: def get_absolute_url(self): return reverse('shop:product_list_by_category', args=[self.slug]) 在settings.url中: urlpatterns =

嗨,我想从slug中反转url 在模型中,我有slug:

slug = models.SlugField(max_length=200, unique=True, allow_unicode=True)
对于获取绝对url:

def get_absolute_url(self):
            return reverse('shop:product_list_by_category', args=[self.slug])
在settings.url中:

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('shop.urls', namespace='shop')),
]
以及在shop.url中:

app_name = 'shop'
urlpatterns = [
    path('', views.product_list, name='product_list'),
    path('<slug:category_slug>/', views.product_list, name='product_list_by_category'),
    path('<int:id>/<slug:slug>/', views.product_detail, name='product_detail'),
]
现在我得到一个错误:

Reverse for 'product_list_by_category' with arguments '('گالری-شلوار',)' not found. 1 pattern(s) tried: ['(?P[-a-zA-Z0-9_]+)/$'] 未找到带参数的“产品列表(按类别)”的反面(“产品列表(按类别)”)”。尝试了1个模式:['(?P[-a-zA-Z0-9_]+)/$']
对于阿拉伯语字母,您必须打开url编码器。您可以通过将此代码添加到
settings.py
文件来完成此操作

ALLOW_UNICODE_SLUGS = True

若要反转任何内容,必须首先使其成为字符串

现在我们可以反转字符串

x = 'Hello World!'
for i in x:
    x = x[::-1]

这和这个问题有什么关系?我应该用重路径代替路径,这是工作。。。但是我很难找到正则表达式(re_path(r'(?P[-\w]+)/$),views.product_list,name='product_list_by_category'),现在我想要一种没有正则表达式的简单方法来解决这个问题
x = 'Hello World!'
for i in x:
    x = x[::-1]