UUID('…') is not JSON serializable

前端 未结 4 1363
生来不讨喜
生来不讨喜 2020-12-05 23:19

I get this error when i try to pass the UUID attribute to url parameter.

urlpatterns = [
    url(r\'^historia-clinica/(?P[W\\d\\-]+)/$\', ClinicH         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 00:06

    For using the UUID in a URL like that, you should pass it as a string:

     return redirect(reverse('namespace:name', kwargs={'uuid' : str(object.id)}))
    

    FYI - it looks like WIMs answer is a bit more thorough. Your regex should certainly be tightened up. If you end up using the string representation of the slug, you'll want a regex like this: [A-Za-z0-9\-]+ which allows for alphanumerics and hyphens.

提交回复
热议问题