0Pricing
Django Academy · レッスン

PermissionsとThrottling

APIを呼び出せるユーザーと頻度を制御します

「PermissionsとThrottling」はCoddyKit上の無料Django Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDjango Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Django Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Who Can Call Your API?

An open API lets anyone read or change your data. Permissions decide who is allowed to do what on each endpoint.

The permission_classes Attribute

You attach access rules with permission_classes on a view or ViewSet. DRF checks them before any action runs.

from rest_framework.permissions import IsAuthenticated

class BookViewSet(viewsets.ModelViewSet):
    permission_classes = [IsAuthenticated]

Built-in Permission Classes

DRF ships ready rules: AllowAny opens a view, IsAuthenticated requires a logged-in user, and IsAdminUser limits it to staff.

Read for All, Write for Members

IsAuthenticatedOrReadOnly is a popular middle ground: anyone can GET, but only logged-in users can POST, PUT, or DELETE.

Setting a Default Globally

Set a project-wide rule in settings.py so every view starts secure unless it opts out.

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.IsAuthenticated',
    ],
}

Writing a Custom Permission

Need your own rule? Subclass BasePermission and return True or False from has_permission for the request.

from rest_framework.permissions import BasePermission

class IsOwner(BasePermission):
    def has_object_permission(self, request, view, obj):
        return obj.owner == request.user

Object-Level Permissions

Use has_object_permission to check a single record, like letting users edit only the posts they own. 🔒

Now, Throttling

Permissions answer who. Throttling answers how often, capping the number of requests a client may send in a time window.

Anon vs User Throttles

DRF offers AnonRateThrottle for unauthenticated visitors and UserRateThrottle for logged-in accounts, so you can be stricter with strangers.

Configuring Rate Limits

Set the limits in settings with DEFAULT_THROTTLE_RATES, using a count plus a period like second, minute, hour, or day.

REST_FRAMEWORK = {
    'DEFAULT_THROTTLE_RATES': {
        'anon': '20/hour',
        'user': '1000/day',
    },
}

What Throttling Protects

Throttling shields you from abuse and runaway scripts. When a client goes over, DRF returns a 429 Too Many Requests response. 🛡️

Quick Check

Let us confirm the difference between the two gatekeepers.

Recap: Access and Rate Limits

You can now gate endpoints with permission classes and protect them with throttle rates. Together they keep your API both safe and stable. 🎉

よくある質問

「PermissionsとThrottling」レッスンは無料ですか?

はい。「PermissionsとThrottling」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Django Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Django Academyコースには全4レッスンが含まれています。

「PermissionsとThrottling」で何を学びますか?

APIを呼び出せるユーザーと頻度を制御します ブラウザで直接実行するハンズオンコードでDjango Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Django Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのDjango Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。

「PermissionsとThrottling」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このDjango Academyレッスンでコードを書いて実行できますか?

はい。すべてのDjango Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. ModelViewSetとRouters
  2. PermissionsとThrottling
  3. Token認証とJWT認証
  4. Filtering、Search、Pagination
← Django Academyに戻る