---
slug: "django-all-auth-password-reset-url"
title: "Django AllAuth のパスワードリセット用のURL を手動で作る"
description: "Mac で Big Sur 以前にあった `find` をクリップボードに送る Service (Quick Action) を作る手順。pbcopy と組み合わせる。"
url: "https://www.ytyng.com/blog/django-all-auth-password-reset-url"
publish_date: "2022-10-17T11:24:00Z"
created: "2022-10-17T11:24:00Z"
updated: "2026-05-11T13:21:53.293Z"
categories: ["Django"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20240615/ef334c929fdf441f997f274ce3d70b5e.png.webp?width=768"
has_video: false
has_music: false
video_urls: []
music_urls: []
lang: "ja"
---

# Django AllAuth のパスワードリセット用のURL を手動で作る

Django all_auth でパスワードリセット URL を作るコードです。

生のパスワードを扱うのと同レベルのリスクがあるので運用には最新の注意を払うこと。


```python
from django.contrib.auth import get_user_model
from django.urls import reverse
from allauth.account.forms import default_token_generator
from allauth.account.utils import user_pk_to_url_str


user = get_user_model().objects.get(id=user_id)

temp_key = default_token_generator.make_token(user)

path = reverse(
    "account_reset_password_from_key",
    kwargs=dict(uidb36=user_pk_to_url_str(user), key=temp_key),
)

print('https://www.example.com' + path)
```
