跳到主要內容

12.DRF-節流

Django rest framework源碼分析(3)----節流


添加節流


自定義節流的方法



  • 限制60s內只能訪問3次


(1)API文件夾下面新建throttle.py,代碼如下:


# utils/throttle.py

from rest_framework.throttling import BaseThrottle
import time
VISIT_RECORD = {} #保存訪問記錄

class VisitThrottle(BaseThrottle):
'''60s內只能訪問3次'''
def __init__(self):
self.history = None #初始化訪問記錄

def allow_request(self,request,view):
#獲取用戶ip (get_ident)
remote_addr = self.get_ident(request)
ctime = time.time()
#如果當前IP不在訪問記錄裏面,就添加到記錄
if remote_addr not in VISIT_RECORD:
VISIT_RECORD[remote_addr] = [ctime,] #鍵值對的形式保存
return True #True表示可以訪問
#獲取當前ip的歷史訪問記錄
history = VISIT_RECORD.get(remote_addr)
#初始化訪問記錄
self.history = history

#如果有歷史訪問記錄,並且最早一次的訪問記錄離當前時間超過60s,就刪除最早的那個訪問記錄,
#只要為True,就一直循環刪除最早的一次訪問記錄
while history and history[-1] < ctime - 60:
history.pop()
#如果訪問記錄不超過三次,就把當前的訪問記錄插到第一個位置(pop刪除最後一個)
if len(history) < 3:
history.insert(0,ctime)
return True

def wait(self):
'''還需要等多久才能訪問'''
ctime = time.time()
return 60 - (ctime - self.history[-1])

(2)settings中全局配置節流


#全局
REST_FRAMEWORK = {
#節流
"DEFAULT_THROTTLE_CLASSES":['API.utils.throttle.VisitThrottle'],
}

(3)現在訪問auth看看結果:



  • 60s內訪問次數超過三次,會限制訪問

  • 提示剩餘多少時間可以訪問



接着訪問



節流源碼分析


(1)dispatch


def dispatch(self, request, *args, **kwargs):
"""
`.dispatch()` is pretty much the same as Django's regular dispatch,
but with extra hooks for startup, finalize, and exception handling.
"""
self.args = args
self.kwargs = kwargs
#對原始request進行加工,豐富了一些功能
#Request(
# request,
# parsers=self.get_parsers(),
# authenticators=self.get_authenticators(),
# negotiator=self.get_content_negotiator(),
# parser_context=parser_context
# )
#request(原始request,[BasicAuthentications對象,])
#獲取原生request,request._request
#獲取認證類的對象,request.authticators
#1.封裝request
request = self.initialize_request(request, *args, **kwargs)
self.request = request
self.headers = self.default_response_headers # deprecate?

try:
#2.認證
self.initial(request, *args, **kwargs)

# Get the appropriate handler method
if request.method.lower() in self.http_method_names:
handler = getattr(self, request.method.lower(),
self.http_method_not_allowed)
else:
handler = self.http_method_not_allowed

response = handler(request, *args, **kwargs)

except Exception as exc:
response = self.handle_exception(exc)

self.response = self.finalize_response(request, response, *args, **kwargs)
return self.response

(2)initial


def initial(self, request, *args, **kwargs):
"""
Runs anything that needs to occur prior to calling the method handler.
"""
self.format_kwarg = self.get_format_suffix(**kwargs)

# Perform content negotiation and store the accepted info on the request
neg = self.perform_content_negotiation(request)
request.accepted_renderer, request.accepted_media_type = neg

# Determine the API version, if versioning is in use.
version, scheme = self.determine_version(request, *args, **kwargs)
request.version, request.versioning_scheme = version, scheme

# Ensure that the incoming request is permitted
#4.實現認證
self.perform_authentication(request)
#5.權限判斷
self.check_permissions(request)
#6.控制訪問頻率
self.check_throttles(request)

(3)check_throttles


裏面有個allow_request


def check_throttles(self, request):
"""
Check if request should be throttled.
Raises an appropriate exception if the request is throttled.
"""
for throttle in self.get_throttles():
if not throttle.allow_request(request, self):
self.throttled(request, throttle.wait())

(4)get_throttles


def get_throttles(self):
"""
Instantiates and returns the list of throttles that this view uses.
"""
return [throttle() for throttle in self.throttle_classes]

(5)thtottle_classes



內置節流類


上面是寫的自定義節流,drf內置了很多節流的類,用起來比較方便。


(1)BaseThrottle



  • 自己要寫allow_request和wait方法

  • get_ident就是獲取ip


class BaseThrottle(object):
"""
Rate throttling of requests.
"""

def allow_request(self, request, view):
"""
Return `True` if the request should be allowed, `False` otherwise.
"""
raise NotImplementedError('.allow_request() must be overridden')

def get_ident(self, request):
"""
Identify the machine making the request by parsing HTTP_X_FORWARDED_FOR
if present and number of proxies is > 0. If not use all of
HTTP_X_FORWARDED_FOR if it is available, if not use REMOTE_ADDR.
"""
xff = request.META.get('HTTP_X_FORWARDED_FOR')
remote_addr = request.META.get('REMOTE_ADDR')
num_proxies = api_settings.NUM_PROXIES

if num_proxies is not None:
if num_proxies == 0 or xff is None:
return remote_addr
addrs = xff.split(',')
client_addr = addrs[-min(num_proxies, len(addrs))]
return client_addr.strip()

return ''.join(xff.split()) if xff else remote_addr

def wait(self):
"""
Optionally, return a recommended number of seconds to wait before
the next request.
"""
return None

(2)SimpleRateThrottle


class SimpleRateThrottle(BaseThrottle):
"""
A simple cache implementation, that only requires `.get_cache_key()`
to be overridden.

The rate (requests / seconds) is set by a `rate` attribute on the View
class. The attribute is a string of the form 'number_of_requests/period'.

Period should be one of: ('s', 'sec', 'm', 'min', 'h', 'hour', 'd', 'day')

Previous request information used for throttling is stored in the cache.
"""
cache = default_cache
timer = time.time
cache_format = 'throttle_%(scope)s_%(ident)s'
scope = None #這個值自定義,寫什麼都可以
THROTTLE_RATES = api_settings.DEFAULT_THROTTLE_RATES

def __init__(self):
if not getattr(self, 'rate', None):
self.rate = self.get_rate()
self.num_requests, self.duration = self.parse_rate(self.rate)

def get_cache_key(self, request, view):
"""
Should return a unique cache-key which can be used for throttling.
Must be overridden.

May return `None` if the request should not be throttled.
"""
raise NotImplementedError('.get_cache_key() must be overridden')

def get_rate(self):
"""
Determine the string representation of the allowed request rate.
"""
if not getattr(self, 'scope', None):
msg = ("You must set either `.scope` or `.rate` for '%s' throttle" %
self.__class__.__name__)
raise ImproperlyConfigured(msg)

try:
return self.THROTTLE_RATES[self.scope]
except KeyError:
msg = "No default throttle rate set for '%s' scope" % self.scope
raise ImproperlyConfigured(msg)

def parse_rate(self, rate):
"""
Given the request rate string, return a two tuple of:
<allowed number of requests>, <period of time in seconds>
"""
if rate is None:
return (None, None)
num, period = rate.split('/')
num_requests = int(num)
duration = {'s': 1, 'm': 60, 'h': 3600, 'd': 86400}[period[0]]
return (num_requests, duration)

def allow_request(self, request, view):
"""
Implement the check to see if the request should be throttled.

On success calls `throttle_success`.
On failure calls `throttle_failure`.
"""
if self.rate is None:
return True

self.key = self.get_cache_key(request, view)
if self.key is None:
return True

self.history = self.cache.get(self.key, [])
self.now = self.timer()

# Drop any requests from the history which have now passed the
# throttle duration
while self.history and self.history[-1] <= self.now - self.duration:
self.history.pop()
if len(self.history) >= self.num_requests:
return self.throttle_failure()
return self.throttle_success()

def throttle_success(self):
"""
Inserts the current request's timestamp along with the key
into the cache.
"""
self.history.insert(0, self.now)
self.cache.set(self.key, self.history, self.duration)
return True

def throttle_failure(self):
"""
Called when a request to the API has failed due to throttling.
"""
return False

def wait(self):
"""
Returns the recommended next request time in seconds.
"""
if self.history:
remaining_duration = self.duration - (self.now - self.history[-1])
else:
remaining_duration = self.duration

available_requests = self.num_requests - len(self.history) + 1
if available_requests <= 0:
return None

return remaining_duration / float(available_requests)

我們可以通過繼承SimpleRateThrottle類,來實現節流,會更加的簡單,因為SimpleRateThrottle裏面都幫我們寫好了


(1)throttle.py


from rest_framework.throttling import SimpleRateThrottle

class VisitThrottle(SimpleRateThrottle):
'''匿名用戶60s只能訪問三次(根據ip)'''
scope = 'NBA' #這裏面的值,自己隨便定義,settings裏面根據這個值配置Rate

def get_cache_key(self, request, view):
#通過ip限制節流
return self.get_ident(request)

class UserThrottle(SimpleRateThrottle):
'''登錄用戶60s可以訪問10次'''
scope = 'NBAUser' #這裏面的值,自己隨便定義,settings裏面根據這個值配置Rate

def get_cache_key(self, request, view):
return request.user.username

(2)settings.py


#全局
REST_FRAMEWORK = {
#節流
"DEFAULT_THROTTLE_CLASSES":['API.utils.throttle.UserThrottle'], #全局配置,登錄用戶節流限制(10/m)
"DEFAULT_THROTTLE_RATES":{
'NBA':'3/m', #沒登錄用戶3/m,NBA就是scope定義的值
'NBAUser':'10/m', #登錄用戶10/m,NBAUser就是scope定義的值
}
}

(3)views.py


局部配置方法


class AuthView(APIView):
.
.
.
# 默認的節流是登錄用戶(10/m),AuthView不需要登錄,這裏用匿名用戶的節流(3/m)
throttle_classes = [VisitThrottle,]   . .

# views.py
from django.shortcuts import render,HttpResponse
from django.http import JsonResponse
from rest_framework.views import APIView
from API import models
from rest_framework.request import Request
from rest_framework import exceptions
from rest_framework.authentication import BaseAuthentication
from API.utils.permission import SVIPPremission,MyPremission
from API.utils.throttle import VisitThrottle

ORDER_DICT = {
1:{
'name':'apple',
'price':15
},
2:{
'name':'dog',
'price':100
}
}

def md5(user):
import hashlib
import time
#當前時間,相當於生成一個隨機的字符串
ctime = str(time.time())
m = hashlib.md5(bytes(user,encoding='utf-8'))
m.update(bytes(ctime,encoding='utf-8'))
return m.hexdigest()


class AuthView(APIView):
'''用於用戶登錄驗證'''

authentication_classes = [] #裏面為空,代表不需要認證
permission_classes = [] #不裏面為空,代表不需要權限
# 默認的節流是登錄用戶(10/m),AuthView不需要登錄,這裏用匿名用戶的節流(3/m)
throttle_classes = [VisitThrottle,]

def post(self,request,*args,**kwargs):
ret = {'code':1000,'msg':None}
try:
user = request._request.POST.get('username')
pwd = request._request.POST.get('password')
obj = models.UserInfo.objects.filter(username=user,password=pwd).first()
if not obj:
ret['code'] = 1001
ret['msg'] = '用戶名或密碼錯誤'
#為用戶創建token
token = md5(user)
#存在就更新,不存在就創建
models.UserToken.objects.update_or_create(user=obj,defaults={'token':token})
ret['token'] = token
except Exception as e:
ret['code'] = 1002
ret['msg'] = '請求異常'
return JsonResponse(ret)


class OrderView(APIView):
'''
訂單相關業務(只有SVIP用戶才能看)
'''

def get(self,request,*args,**kwargs):
self.dispatch
#request.user
#request.auth
ret = {'code':1000,'msg':None,'data':None}
try:
ret['data'] = ORDER_DICT
except Exception as e:
pass
return JsonResponse(ret)


class UserInfoView(APIView):
'''
訂單相關業務(普通用戶和VIP用戶可以看)
'''
permission_classes = [MyPremission,] #不用全局的權限配置的話,這裏就要寫自己的局部權限
def get(self,request,*args,**kwargs):

print(request.user)
return HttpResponse('用戶信息')

說明:



  • API.utils.throttle.UserThrottle 這個是全局配置(根據ip限制,10/m)

  • DEFAULT_THROTTLE_RATES --->>>設置訪問頻率的

  • throttle_classes = [VisitThrottle,] --->>>局部配置(不適用settings裏面默認的全局配置)


總結


基本使用



  • 創建類,繼承BaseThrottle, 實現:allow_request ,wait

  • 創建類,繼承SimpleRateThrottle, 實現: get_cache_key, scope='NBA' (配置文件中的key)


全局


   #節流
"DEFAULT_THROTTLE_CLASSES":['API.utils.throttle.UserThrottle'], #全局配置,登錄用戶節流限制(10/m)
"DEFAULT_THROTTLE_RATES":{
'NBA':'3/m', #沒登錄用戶3/m,NBA就是scope定義的值
'NBAUser':'10/m', #登錄用戶10/m,NBAUser就是scope定義的值
}
}

局部


throttle_classes = [VisitThrottle,]

所有代碼


認證、權限和節流


# MyProject/urls.py

from django.contrib import admin
from django.urls import path
from API.views import AuthView,OrderView,UserInfoView

urlpatterns = [
path('admin/', admin.site.urls),
path('api/v1/auth/',AuthView.as_view()),
path('api/v1/order/',OrderView.as_view()),
path('api/v1/info/',UserInfoView.as_view()),
]

#全局 settings.py
REST_FRAMEWORK = {
#認證
"DEFAULT_AUTHENTICATION_CLASSES":['API.utils.auth.Authentication',],
#權限
"DEFAULT_PERMISSION_CLASSES":['API.utils.permission.SVIPPermission'],
#節流
"DEFAULT_THROTTLE_CLASSES":['API.utils.throttle.UserThrottle'], #全局配置,登錄用戶節流限制(10/m)
"DEFAULT_THROTTLE_RATES":{
'NBA':'3/m', #沒登錄用戶3/m,NBA就是scope定義的值
'NBAUser':'10/m', #登錄用戶10/m,NBAUser就是scope定義的值
}
}

# API/models.py


from django.db import models

class UserInfo(models.Model):
USER_TYPE = (
(1,'普通用戶'),
(2,'VIP'),
(3,'SVIP')
)

user_type = models.IntegerField(choices=USER_TYPE)
username = models.CharField(max_length=32)
password = models.CharField(max_length=64)

class UserToken(models.Model):
user = models.OneToOneField(UserInfo,on_delete=models.CASCADE)
token = models.CharField(max_length=64)

# API/views.py

from django.shortcuts import render,HttpResponse
from django.http import JsonResponse
from rest_framework.views import APIView
from API import models
from rest_framework.request import Request
from rest_framework import exceptions
from rest_framework.authentication import BaseAuthentication
from API.utils.permission import SVIPPermission,MyPermission
from API.utils.throttle import VisitThrottle

ORDER_DICT = {
1:{
'name':'apple',
'price':15
},
2:{
'name':'dog',
'price':100
}
}

def md5(user):
import hashlib
import time
#當前時間,相當於生成一個隨機的字符串
ctime = str(time.time())
m = hashlib.md5(bytes(user,encoding='utf-8'))
m.update(bytes(ctime,encoding='utf-8'))
return m.hexdigest()


class AuthView(APIView):
'''用於用戶登錄驗證'''

authentication_classes = [] #裏面為空,代表不需要認證
permission_classes = [] #不裏面為空,代表不需要權限
# 默認的節流是登錄用戶(10/m),AuthView不需要登錄,這裏用匿名用戶的節流(3/m)
throttle_classes = [VisitThrottle,]

def post(self,request,*args,**kwargs):
ret = {'code':1000,'msg':None}
try:
user = request._request.POST.get('username')
pwd = request._request.POST.get('password')
obj = models.UserInfo.objects.filter(username=user,password=pwd).first()
if not obj:
ret['code'] = 1001
ret['msg'] = '用戶名或密碼錯誤'
#為用戶創建token
token = md5(user)
#存在就更新,不存在就創建
models.UserToken.objects.update_or_create(user=obj,defaults={'token':token})
ret['token'] = token
except Exception as e:
ret['code'] = 1002
ret['msg'] = '請求異常'
return JsonResponse(ret)


class OrderView(APIView):
'''
訂單相關業務(只有SVIP用戶才能看)
'''

def get(self,request,*args,**kwargs):
self.dispatch
#request.user
#request.auth
ret = {'code':1000,'msg':None,'data':None}
try:
ret['data'] = ORDER_DICT
except Exception as e:
pass
return JsonResponse(ret)


class UserInfoView(APIView):
'''
訂單相關業務(普通用戶和VIP用戶可以看)
'''
permission_classes = [MyPermission,] #不用全局的權限配置的話,這裏就要寫自己的局部權限
def get(self,request,*args,**kwargs):

print(request.user)
return HttpResponse('用戶信息')

# API/utils/auth/py

from rest_framework import exceptions
from API import models
from rest_framework.authentication import BaseAuthentication


class Authentication(BaseAuthentication):
'''用於用戶登錄驗證'''
def authenticate(self,request):
token = request._request.GET.get('token')
token_obj = models.UserToken.objects.filter(token=token).first()
if not token_obj:
raise exceptions.AuthenticationFailed('用戶認證失敗')
#在rest framework內部會將這兩個字段賦值給request,以供後續操作使用
return (token_obj.user,token_obj)

def authenticate_header(self, request):
pass

# utils/permission.py

from rest_framework.permissions import BasePermission

class SVIPPermission(BasePermission):
message = "必須是SVIP才能訪問"
def has_permission(self,request,view):
if request.user.user_type != 3:
return False
return True


class MyPermission(BasePermission):
def has_permission(self,request,view):
if request.user.user_type == 3:
return False
return True

# utils/throttle.py
#
# from rest_framework.throttling import BaseThrottle
# import time
# VISIT_RECORD = {} #保存訪問記錄
#
# class VisitThrottle(BaseThrottle):
# '''60s內只能訪問3次'''
# def __init__(self):
# self.history = None #初始化訪問記錄
#
# def allow_request(self,request,view):
# #獲取用戶ip (get_ident)
# remote_addr = self.get_ident(request)
# ctime = time.time()
# #如果當前IP不在訪問記錄裏面,就添加到記錄
# if remote_addr not in VISIT_RECORD:
# VISIT_RECORD[remote_addr] = [ctime,] #鍵值對的形式保存
# return True #True表示可以訪問
# #獲取當前ip的歷史訪問記錄
# history = VISIT_RECORD.get(remote_addr)
# #初始化訪問記錄
# self.history = history
#
# #如果有歷史訪問記錄,並且最早一次的訪問記錄離當前時間超過60s,就刪除最早的那個訪問記錄,
# #只要為True,就一直循環刪除最早的一次訪問記錄
# while history and history[-1] < ctime - 60:
# history.pop()
# #如果訪問記錄不超過三次,就把當前的訪問記錄插到第一個位置(pop刪除最後一個)
# if len(history) < 3:
# history.insert(0,ctime)
# return True
#
# def wait(self):
# '''還需要等多久才能訪問'''
# ctime = time.time()
# return 60 - (ctime - self.history[-1])

from rest_framework.throttling import SimpleRateThrottle

class VisitThrottle(SimpleRateThrottle):
'''匿名用戶60s只能訪問三次(根據ip)'''
scope = 'NBA' #這裏面的值,自己隨便定義,settings裏面根據這個值配置Rate

def get_cache_key(self, request, view):
#通過ip限制節流
return self.get_ident(request)

class UserThrottle(SimpleRateThrottle):
'''登錄用戶60s可以訪問10次'''
scope = 'NBAUser' #這裏面的值,自己隨便定義,settings裏面根據這個值配置Rate

def get_cache_key(self, request, view):
return request.user.username
本站聲明:網站內容來源於博客園,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】



※教你寫出一流的銷售文案?



※廣告預算用在刀口上,台北網頁設計公司幫您達到更多曝光效益



※回頭車貨運收費標準



※別再煩惱如何寫文案,掌握八大原則!



※超省錢租車方案



※產品缺大量曝光嗎?你需要的是一流包裝設計!



Orignal From: 12.DRF-節流

留言

這個網誌中的熱門文章

架構設計 | 異步處理流程,多種實現模式詳解

本文源碼:GitHub·點這裏 || GitEE·點這裏 一、異步處理 1、異步概念 異步處理不用阻塞當前線程來等待處理完成,而是允許後續操作,直至其它線程將處理完成,並回調通知此線程。 必須強調一個基礎邏輯,異步是一種設計理念,異步操作不等於多線程,MQ中間件,或者消息廣播,這些是可以實現異步處理的方式。 同步處理和異步處理相對,需要實時處理並響應,一旦超過時間會結束會話,在該過程中調用方一直在等待響應方處理完成並返回。同步類似電話溝通,需要實時對話,異步則類似短信交流,發送消息之後無需保持等待狀態。 2、異步處理優點 雖然異步處理不能實時響應,但是處理複雜業務場景,多數情況都會使用異步處理。 異步可以解耦業務間的流程關聯,降低耦合度; 降低接口響應時間,例如用戶註冊,異步生成相關信息表; 異步可以提高系統性能,提升吞吐量; 流量削峰即把請求先承接下來,然後在異步處理; 異步用在不同服務間,可以隔離服務,避免雪崩; 異步處理的實現方式有很多種,常見多線程,消息中間件,發布訂閱的廣播模式,其根據邏輯在於先把請求承接下來,放入容器中,在從容器中把請求取出,統一調度處理。 注意 :一定要監控任務是否產生積壓過度情況,任務如果積壓到雪崩之勢的地步,你會感覺每一片雪花都想勇闖天涯。 3、異步處理模式 異步流程處理的實現有好多方式,但是實際開發中常用的就那麼幾種,例如: 基於接口異步響應,常用在第三方對接流程; 基於消息生產和消費模式,解耦複雜流程; 基於發布和訂閱的廣播模式,常見系統通知 異步適用的業務場景,對數據強一致性的要求不高,異步處理的數據更多時候追求的是最終一致性。 二、接口響應異步 1、流程描述 基於接口異步響應的方式,有一個本地業務服務,第三方接口服務,流程如下: 本地服務發起請求,調用第三方服務接口; 請求包含業務參數,和成功或失敗的回調地址; 第三方服務實時響應流水號,作為該調用的標識; 之後第三方服務處理請求,得到最終處理結果; 如果處理成功,回調本地服務的成功通知接口; 如果處理失敗,回調本地服務的失敗通知接口; 整個流程基於部分異步和部分實時的模式,完整處理; 注意 :如...

.NET Core前後端分離快速開發框架(Core.3.0+AntdVue)

.NET Core前後端分離快速開發框架(Core.3.0+AntdVue) 目錄 引言 時間真快,轉眼今年又要過去了。回想今年,依次開源發布了 Colder.Fx.Net.AdminLTE(254Star) 、 Colder.Fx.Core.AdminLTE(335Star) 、 DotNettySocket(82Star) 、 IdHelper(47Star) ,這些框架及組件都是本着以實際出發,實事求是的態度,力求提高開發效率(我自己都是第一個使用者),目前來看反響不錯。但是隨着前端和後端技術的不斷變革,尤其是前端,目前大環境已經是前後端完全分離為主的開發模式,在這樣的大環境和必然趨勢之下,傳統的MVC就顯得有些落伍了。在這樣的背景下,一款前後端分離的.NET開發框架就顯得尤為必要,由此便定了框架的升級目標: 前後端分離 。 首先後端技術的選擇,從目前的數據來看,.NET Core的發展遠遠快於.NET Framework,最簡單的分析就是Colder.Fx.Core.AdminLTE發布比Colder.Fx.Net.AdminLTE晚,但是星星卻後來居上而且比前者多30%,並且這個差距在不斷擴大,由點及面的分析可以看出我們廣大.NET開發人員學習的熱情和积極向上的態度,並不是某些人所認為的那麼不堪( 走自己的路,讓別人說去吧 )。大環境上微軟积極擁抱開源,大力發展.NET Core, 可以說前途一片光明。因此後端決定採用 .NET Core3.0 ,不再浪費精力去支持.NET Framework。 然後是前端技術選擇,首選是三大js框架選擇,也是從實際出發,Vue相對其它而言更加容易上手,並且功能也毫不遜色,深得各種大小公司喜歡,如果偏要說缺點的話,那就是對TS支持不行,但是即將發布Vue3.0肯定會改變這一缺陷。選擇了Vue之後,然後就是UI框架的選擇了,這裏的選擇更多了,我選擇了Ant Design Vue,理由便是簡潔方便,十分符合我的設計理念。 技術選型完畢之後便...

台北市住宅、社區建創儲能設備 最高可獲600萬元補助

為了推廣分散式發電,台北市環保局預計補助1億元供住宅社區設置創能、儲能設備,計有3種方案可供選擇。環保局說明,每案補助額度不超過建制總經費49%,社區每案最高可獲200萬至600萬元補助,住宅每案補助上限100萬元,5月1日起開放申請。 環保局說明,台北市溫室氣體排放量7成以上來自住商部門,其中以使用電力造成間接溫室氣體排放為大宗,台北市平均年用電量約159.86億度,1度電約等同排放0.5公斤二氧化碳,若想達成2050年淨零排放目標,僅靠節能減碳無法達成,必須發展綠色創能、儲能,並且參考歐洲、日本的做法,採分散式發電方式,推廣到社區、住家、商辦,達到供電自給自足目標。 因此,環保局推出「台北市住宅社區創能儲能及節能補助計畫」,補助對象為台北市轄內房屋所有權人及社區管理委員會,補助方案共計3種,每一申請人或每一場址僅能獲1次補助,每案補助額度不超過建置總經費49%為限,5月1日到7月31日開放申請,但補助經費用完即停止申請。 環保局說明,方案A補助對象以社區為主,公共區域申請創能儲能及節能項目,每案補助上限新台幣600萬元;方案B分為住宅或社區公共區域申請創能搭配儲能項目(創能或儲能方案不得單獨申請),社區每案補助上限新台幣400萬元,住宅每案補助上限100萬元。方案C補助對象也是社區,公共區域申請節能項目,每案補助上限新台幣200萬元。 網頁設計 最專業,超強功能平台可客製,窩窩以「數位行銷」「品牌經營」「網站與應用程式」「印刷品設計」等四大主軸,為每一位客戶客製建立行銷脈絡及洞燭市場先機,請問 台中電動車 哪裡在賣比較便宜可以到台中景泰電動車門市去看看總店:臺中市潭子區潭秀里雅潭路一段102-1號。 電動車補助 推薦評價好的 iphone維修 中心擁有專業的維修技術團隊,同時聘請資深iphone手機維修專家,現場說明手機問題,快速修理,沒修好不收錢住家的頂樓裝 太陽光電 聽說可發揮隔熱功效一線推薦東陽能源擁有核心技術、產品研發、系統規劃設置、專業團隊的太陽能發電廠商。 網頁設計 一頭霧水該從何著手呢? 回頭車 貨運收費標準宇安交通關係企業,自成立迄今,即秉持著「以誠待人」、「以實處事」的企業信念 台中搬家公司 教你幾個打包小技巧,輕鬆整理裝箱!還在煩惱搬家費用要多少哪?台中大展搬家線上試算搬家費用,從此不再擔心「物品怎麼計費」、「多...