Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run python script inside django project?

I am unable to run python script inside my django project.

  1. I have create a directory with mkdir scripts
  2. Then I use touch scripts/__init__.py
  3. Then I create my python script using touch scripts/update_keyword.py
  4. here is the code of my script

def run():
    # Fetch all questions
    print("run script")


Then I run my script with the help of the following command:

python manage.py runscript update_keyword.py

Now I am getting following error:

Unknown command: 'runscript'
Type 'manage.py help' for usage.


I have follow this blog https://django-extensions.readthedocs.io/en/latest/runscript.html . Kindly Help.

like image 517
Mr.Robot Avatar asked Oct 31 '25 22:10

Mr.Robot


2 Answers

Django does not know this command since it is not listed anywhere. When you want to run a command with manage.py, use Django's Admin Command.

EDIT Or if you really want to use django_extensions for some reason, use their GitHub docs as reference. There it states you need to add this app to INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'django_extensions',
    ...
)
like image 105
gonczor Avatar answered Nov 02 '25 12:11

gonczor


Check the installation:

https://django-extensions.readthedocs.io/en/latest/installation_instructions.html

I guess you have missed this:

INSTALLED_APPS = (
    ...
    'django_extensions',
)
like image 45
ikcam Avatar answered Nov 02 '25 11:11

ikcam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!