在我的django应用程序中,我试图获取端点视图的绝对URL,其定义如下:
class ProductViewSet(viewsets.ModelViewSet):
lookup_field = 'uuid'
serializer_class = ProductSerializer
permission_classes = (AllowAny,)
def get_queryset(self):
...
return queryset
urls.py
router = routers.SimpleRouter()
router.register(r'products', ProductViewSet, base_name="product")
urlpatterns = [
url(r'^', include(router.urls)),
]
models.py
from django.core.urlresolvers import reverse
class Product(models.Model):
uuid = models.UUIDField(default=uuid1)
def get_absolute_url(self):
return reverse('product', kwargs={'uuid': self.uuid})
然而,当我这样做并尝试获取特定产品的网址时,我收到错误Reverse for 'product' with arguments '()' and keyword arguments '{'uuid': UUID('d89-f530')}' not found. 0 pattern(s) tried: []
我尝试了不同的东西,但错误仍然相同,我不确定urlresolver
如何与DRF路由器视图一起使用。
正如旁注,我正在使用django 1.10
对此的任何帮助都将非常感激 谢谢