Django,DRF,Nginx,Uwsgi环境实现universal link,根路由apple-app-site-association功能支持
一个Django rest framework开发的web服务,需要支持iOS的universal link功能。
需要将apple-app-site-association文件放在域名的目录下。实现xxx.xx/apple-app-site-association即可访问下载。
需要处理三处。
1、django的setting配置静态文件
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, STATIC_URL)
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,MEDIA_URL)
2、nginx的conf配置location
location /static {
alias /home/project/app/static;
}
3、Views中实现get方法(重要)
class apple_association_view(APIView):
authentication_classes = []
permission_classes=[]
def get(self,*args, **kwargs):
# 指定需要下载的文件
static_root = settings.STATIC_ROOT
download_file = os.path.join(static_root, 'apple-app-site-association')
response = HttpResponse(download_file)
response['Content-Type'] = 'application/octet-stream' #设置头信息,告诉浏览器这是个文件
response['Content-Disposition'] = 'attachment;filename="apple-app-site-association"'
return response
最后配置url即可path('apple-app-site-association',apple_association_view.as_view()),
版权属于:邢迪的平行时空
本文链接:https://xingdi.me/archives/95.html
本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可