我有模型管理视图,我添加了如下自定义视图。然后我使用 jQuery 上传一个 csv 文件。
def get_urls(self):
urls = super(MyAdminView, self).get_urls()
my_urls = [
path('upload_csv/', self.upload_csv, name='upload_csv'),
]
return my_urls + urls
Run Code Online (Sandbox Code Playgroud)
我的问题是我不知道如何在测试中将 url 反向到该视图。
我正在尝试通过新的 FCM api 协议实现发送通知。我经历了身份验证请求,我也在谷歌控制台中启用了 api。现在,当我发送请求时,我收到错误请求 400 错误。除了错误代码和错误消息外,响应不包含任何其他信息。甚至原因字段显示“错误请求”。我正在使用FCM api docs实现它。
def fcm_test():
FCM_URL = "https://fcm.googleapis.com/v1/projects/MY_PROJECT_NAME/messages:send"
my_token = "device-token"
payload = {
"massage": {
"token": my_token,
"notification": {
"body": "body",
"title": "title"
}
}
}
payload = json.dumps(payload)
headers = {
"Authorization": "Bearer {auth_token}".format(auth_token=_get_authentication_token()),
"Content-Type": "application/json; UTF-8",
}
try:
request = moves.urllib.request.Request(FCM_URL, payload.encode('utf-8'), headers)
response = moves.urllib.request.urlopen(request, timeout=10)
except Exception as e:
pass
return
Run Code Online (Sandbox Code Playgroud)