RuntimeError: You called this URL via PUT, but the URL doesn't end in a slash and you have APPEND_SLASH set. Django can't redirect to the slash URL while maintaining PUT data. Change your form to point to localhost:8888/app/edit_user/16/ (note the trailing slash), or set APPEND_SLASH=False in your Django settings.
[08/Mar/2024 15:31:29] "PUT /app/edit_user/16 HTTP/1.1" 500 72933
这个错误是由于Django默认情况下需要在URL末尾加上斜杠(/
),但是在发送PUT请求时,不能自动重定向到带有斜杠的URL。为了解决这个问题,你可以做以下几种修改之一:
-
在发送请求时带上斜杠:确保在发送PUT请求时,在URL末尾加上斜杠,如
http://localhost:8888/app/edit_user/16/
。 -
在Django设置中禁用自动添加斜杠:你可以在Django的
settings.py
文件中将APPEND_SLASH
设置为False
,这样Django就不会自动添加斜杠了。但是请注意,这样做可能会影响其他部分的URL解析和重定向。# settings.py APPEND_SLASH = False
在前端发送请求时添加斜杠:如果你无法修改Django的设置或者不想禁用自动添加斜杠功能,你可以在前端发送PUT请求时手动添加斜杠。