Include a manage.py command to create user token · Issue #5173 · encode/django-rest-framework (original) (raw)

Checklist

Steps to reproduce

After I create a user (myuser), if I want to create an auth token for it, I have to:

  1. open a shell: ./manage.py shell
  2. execute:
from django.contrib.auth.models import User
from rest_framework.authtoken.models import Token

user = User.objects.get(username='myuser')
Token.objects.get_or_create(user=user)

Expected behavior

It would be useful to have something like:

./manage.py drf-token-create myuser
Token for user 'myuser' created: fasd8fgashfas8fygasfdyhasidfaoiufdgaf

Actual behavior

There is no such command.

Note

If there is enough interest for this feature and you think it may be useful for other people, I'm happy to code it in my spare time. I would be glad to finally contribute back to DRF with some code.