简体   繁体   English

升级到1.10或1.11后,Django将URL参数命名为不再有效

[英]Django named URL parameters no longer working after upgrade to 1.10 or 1.11

I have an old Django app which uses the URL template tag this way: 我有一个旧的Django应用程序,它使用URL模板标记:

{% url 'smart_service.views.view_name' %}

So far it worked greatly, but after the update to version 1.10 nothing works anymore and any use made that way returns NoReverseMatch . 到目前为止,它工作得很好,但是在更新到版本1.10之后,没有任何东西可以工作了,任何使用都会返回NoReverseMatch

I can solve this problem by putting app_name = 'smart_service' into my urls.py file and by changing the url tag to this: 我可以通过将app_name = 'smart_service'放入我的urls.py文件并将url标记更改为此来解决此问题:

{% url 'smart_service:view_name' %}

This is a tedious task and very prone to errors, I'd like to avoid it unless strictly necessary. 这是一项繁琐的任务,很容易出错,除非有必要,否则我想避免它。

Is the first use-case been deprecated? 第一个用例是否已被弃用? If not, why isn't it working anymore? 如果没有,为什么它不再起作用? Are there specific advantages in using one or the other? 使用其中一种还有其他特殊优势吗?

You can't avoid this change when you upgrade to Django 1.10+. 升级到Django 1.10+时,无法避免此更改。

Support for reversing urls using the dotted Python path was deprecated in Django 1.8 and removed in 1.10 . 使用虚线Python路径支持反转网址在Django 1.8已弃用, 在1.10中 删除

You must change your {% url %} tags to use the view name, eg 您必须更改{% url %}标记才能使用视图名称,例如

{% url 'view_name' %}

If you add a namespace to your urls.py , for example app_name = 'smart_service' , then you must include the namespace in the {% url %} tag. 如果向urls.py添加名称空间,例如app_name = 'smart_service' ,则必须在{% url %}标记中包含名称空间。

{% url 'smart_service:view_name' %}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM