---
slug: "permission-test-for-model-in-django-template"
title: "Djangoで、テンプレート内でモデルに対してのパーミッションがあるかを確認する"
description: "Django のテンプレート言語で、ログインユーザーがモデルに対してのパーミッションを持っているかを判定する例です。\n\nperms というテンプレート変数がデフォルトで存在しており、それを使うことで判定できます。"
url: "https://www.ytyng.com/blog/permission-test-for-model-in-django-template"
publish_date: "2023-08-08T11:52:38Z"
created: "2023-08-08T11:52:38Z"
updated: "2026-02-26T01:13:07.932Z"
categories: []
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20250705/ca22b55a7798471db3fa5b80cedf76bb.png.webp?width=768"
has_video: true
has_music: true
video_urls: ["https://media.ytyng.net/ytyng-blog/289/featured-video-1.mp4", "https://media.ytyng.net/ytyng-blog/289/featured-video-2.mp4", "https://media.ytyng.net/ytyng-blog/289/featured-video-3.mp4"]
music_urls: ["https://media.ytyng.net/ytyng-blog/289/featured-music-289-3.mp3", "https://media.ytyng.net/ytyng-blog/289/featured-music-289-4.mp3"]
lang: "ja"
---

# Djangoで、テンプレート内でモデルに対してのパーミッションがあるかを確認する

Django のテンプレート言語で、ログインユーザーがモデルに対してのパーミッションを持っているかを判定する例です。

perms というテンプレート変数がデフォルトで存在しており、それを使うことで判定できます。


```html
{% if perms.myapp.view_mymodel %}
  <li class="nav-item">
    <a href="{% url 'admin:myapp_mymodel_changelist' %}" class="nav-link">管理ページ</a>
  </li>
{% endif %}
```
