Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i use django's runscript?

Tags:

django

I am trying to run a script using django's runscript. I followed everything in the documentation. Did i miss something?

Here is the files that i created

But when i tried running it from the command line. it says unknown command 'runscript'

(env) C:\Users\MIS\hr system\hr_project>python manage.py runscript automail.py Unknown command: 'runscript'

like image 203
michael ababao Avatar asked Apr 30 '19 01:04

michael ababao


1 Answers

You need to install django-extensions if you want the runscript command. If you don't want to do that, you can:

  • Run your script directly. Keep in mind that you need to specify the Django settings module as such:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "your_project_name.settings")

from your_project.models import SomeModel

# Your code goes here...
  • Make a custom manage.py command. You can use the official how-to: https://docs.djangoproject.com/en/2.2/howto/custom-management-commands/
like image 153
Filip Dimitrovski Avatar answered Sep 19 '22 13:09

Filip Dimitrovski