For some weird reason, reverse function is not working even though my url has no arguments.
Url.py:
from django.urls import path
from . import views
urlpatterns = [
path("api/v2/app/nextdialog", views.NextDialog.as_view(), name="app-next-dialog"),
]
views.py:
class StartAssessment(generics.GenericAPIView):
def post(self, request, *args, **kwargs):
data = request.data
request = build_rp_request(data)
response = post_to_app_start_assessment(request)
path = get_path(response)
step = get_step(response)
data["path"] = path
data["step"] = step
request = build_rp_request(data)
app_response = post_to_app(request, path)
message = format_message(app_response)
return Response(message, status=status.HTTP_200_OK)
functions.py:
def get_endpoint(payload):
head = {
"Content-Type": "application/json",
}
url = reverse("app-next-dialog")
response = requests.post(url, data=json.dumps(payload), headers=head)
return response
When I run this I get the following error.
url = reverse("app-next-dialog")
TypeError: reverse() takes exactly 2 arguments (1 given)
Please does anyone have an idea what's wrong here. I wouldn't think I need to add any other arguments. Thanks
CodePudding user response:
Are you using Django reverse
or DRF reverse
?
Django reverse returns a relative URI when DRF reverse can return an absolute URI.
Django reverse
takes 1 argument so this should work
url = reverse("app-next-dialog")
But DRF reverse
takes two arguments like:
url = reverse("app-next-dialog", request=request)
Check your imports