URL配置错误Djang

2024-06-16 10:38:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个链接

 a href="editYou/{{costumer.slug}}"

和URL部分

(r'editYou/<?P(costumerSlug>.*)/$', 'editYou'),

指向方法

def editYou(request, costumerSlug):

但Django显示了一个错误:

The current URL, profile/editYou/es, didn't match any of these.

你怎么帮我找到原因?你知道吗


Tags: thedjango方法url链接requestdef错误
2条回答

你的模式是错误的,应该是

r'editYou/(?P<costumerSlug>.*)/$'
#         ^^^^
#   not   <?P(costumerSlug>.*)

最好将URL命名为:

(r'editYou/(?P<costumerSlug>.*)/$', 'editYou', name="edit"),

然后在模板中,可以使用:

 a href="{% url edit costumer.slug %}"

相关问题 更多 >