python
config_error
ai_generated
true
django.core.exceptions.ImproperlyConfigured: URL模式'myapp/'没有尾斜杠。
django.core.exceptions.ImproperlyConfigured: The URL pattern 'myapp/' does not have a trailing slash.
ID: python/django-redirect-without-trailing-slash
80%修复率
83%置信度
0证据数
2024-07-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
URL模式未定义尾斜杠,但Django的APPEND_SLASH设置期望有斜杠。
English
URL patterns defined without trailing slash, but Django's APPEND_SLASH setting expects slashes.
解决方案
-
95% 成功率
Ensure all URL patterns end with a slash: path('myapp/', views.my_view). -
90% 成功率
Use re_path with regex that allows optional trailing slash.
无效尝试
常见但无效的做法:
-
70% 失败
Disables automatic slash appending, may break expected URL behavior and cause 404s.
-
60% 失败
Complex and unnecessary; best to define URLs consistently with slashes.