nothing happens after running python manage.py shell < script.py

Question:

This is my first time trying to run a script. I’m trying to hash previously stored plain text in my db.

Anyway I created script.py file in my project folder it doesn’t seem to do anything what am I missing?

The command I’m running in my virtual env:
python manage.py shell < script.py

My script.py file:

from django.contrib.auth.hashers import make_password
from myapp.models import User


def hash_existing_passwords():
    for user in User.objects.all():
        user.user_password = make_password(user.user_password)
        user.save()
Asked By: JHS99

||

Answers:

As already explained by Sir @SunderamDubey in the above comment:

Try adding the line hash_existing_passwords() at the end of script.py, this will execute the function when you run the python manage.py shell < script.py command.

Answered By: Dishant singhal