def download_key(request, key_file):
user = request.user
if not user.is_active:
return HttpResponseForbidden(u'此文件需要登录才可访问')
key = KeysManager.objects.get(key_file=key_file)
if not user.is_superuser or user not in key.who_can_see.all():
return HttpResponseForbidden(u'您没有权限访问些文件')
key_file_path = os.path.join(key.key_file.storage.location, key.key_file.name)
ret = FileResponse(open(key_file_path))
ret['Content-Disposition'] = 'attachment; filename="%s"' % key.key_file.name
return ret
This may not be an issue that the framework should manage. You can write something for permission management, and then use the decorator to hang it on the view function to determine whether it has sufficient permissions.
Done, thank you.
1.Write a view
2. Hang on the url
This may not be an issue that the framework should manage. You can write something for permission management, and then use the decorator to hang it on the view function to determine whether it has sufficient permissions.