使用乔瑟,我试图为我的前端生成正确的url。我必须在我的url字符串中有个符号,而Djoser在将它发送到我的前端之前先格式化这个url。网址看起来是:
https://localhost:4200/activate?id=MjA&token=540-cad5f834d5508ebdd78e但是我得到的最后结果看起来像注释"amp;“after &
http://localhost:4200/activate?id=MjE&token=541-c0437e0afd6261fd4833我尝试了下面的解决方案,但它们都不适用于(\u0026, {\u0026}, {\u0026:c}, &&)
print("https://localhost:4200/activate?id={uid}\u0026token={token}".format(uid="MjA", token="540-cad5f834d5508ebdd78e"))
print("https://localhost:4200/activate?id={uid}{\u0026}token={token}".format(uid="MjA", token="540-cad5f834d5508ebdd78e")) <-- returns KeyError: '&'
print("https://localhost:4200/activate?id={uid}{\u0026:c}token={token}".format(uid="MjA", token="540-cad5f834d5508ebdd78e")) <-- returns KeyError: '&'注意:I不能直接更改format()部件中的代码,这将由Djoser处理。我可以传递的部分实际上只是将字符串值赋值给激活url,比如:'ACTIVATION_URL': 'activate?id={uid}{\u0026:c}token={token}',,所以我必须用这个字符串编写我的解决方案。
NOTE2:,我在木星上试过,一切都很好,当我这样做的时候,我得到了正确的url:
print("https://localhost:4200/activate?id={uid}\u0026token={token}".format(uid="MjA", token="540-cad5f834d5508ebdd78e"))

直接将&添加到前端相同的url中,amp;在&后面
更新 Djoser模板覆盖
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
...
},
]

发布于 2019-02-21 01:13:30
https://stackoverflow.com/questions/54797037
复制相似问题