# django.urls.exceptions.NoReverseMatch: 使用参数 '('',)' 反向解析 'product-detail' 未找到。尝试了1个模式：['product/<int:pk>/']

- **ID:** `python/django-url-reverse-args-error`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在使用reverse()或{% url %}标签时传递空字符串或非整数作为主键。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   Check that pk is not None and is an integer: if pk: url = reverse('product-detail', args=[pk])
   ```
2. **** (90% 成功率)
   ```
   Use get_object_or_404 to ensure object exists before reversing.
   ```

## 无效尝试

- **** — If pk is empty, it still fails; need to ensure pk is valid integer. (80% 失败率)
- **** — Hides the error and may lead to broken links. (70% 失败率)
