Django-rest-framework:没有名为'rest_framework.reverse_lazy'的模块

时间:2017-12-20 12:41:03

标签: django django-rest-framework

我已经尝试过逆转DRF了吗

from rest_framework.reverse import reverse
reverse("posts-api:article_year_month",args=(2017,1))

'/api/gaurnitai/posts/2017/1'

而reverse_lazy不起作用:

from rest_framework.reverse_lazy import reverse_lazy
reverse_lazy("posts-api:article_year_month",args=(2017,1),request=request)

ModuleNotFoundError: No module named 'rest_framework.reverse_lazy'

1 个答案:

答案 0 :(得分:1)

您的导入应该是

from rest_framework.reverse import reverse_lazy