Python 当参数包含特殊字符或空格时,/profile/preview/处的NoReverseMatch
仅当参数包含特殊字符或空格时,才在/profile/preview/处获取NoReverseMatch。对于没有特殊字符或空格的参数,可以使用Python 当参数包含特殊字符或空格时,/profile/preview/处的NoReverseMatch,python,django,Python,Django,仅当参数包含特殊字符或空格时,才在/profile/preview/处获取NoReverseMatch。对于没有特殊字符或空格的参数,可以使用 返回HttpResponseRedirect(反向('profile-by-username',kwargs={'username':c.username})) url(r'^preview/(?p\d+/?$),views.preview,name='profile-preview')我认为您需要在url中修复正则表达式,以便接受特殊字符@$*\uuc
返回HttpResponseRedirect(反向('profile-by-username',kwargs={'username':c.username}))
url(r'^preview/(?p\d+/?$),views.preview,name='profile-preview')
我认为您需要在url中修复正则表达式,以便接受特殊字符@$*\uucode>,如下所示:
url(r'^profile/(?P<username>[-\w.@+*$ -]+)/?$', views.user, name='profile-by-username')
url(r'^profile/(?P[-\w.@+*$-]+)/?$,views.user,name='profile-by-username')
您可以在此处测试此正则表达式:您发布了配置文件预览
,而您重定向到按用户名配置文件
问题仅适用于用户名包含特殊字符或空格的情况。什么是导致您出现问题的特殊字符?以下是一些:@$*\u您可以共享用户名的值吗?是的。它是pr@tik.ERROR:profile by username与参数“()”和关键字参数“{”username:u”相反pr@tik找不到“}”。尝试了1个模式:['(?P[\\w\\.\\s-]+)/?$']
url中的正则表达式(根据错误)和我提供的正则表达式([-\w.@+*$]
)不相同。