How replace "./manage.py < some_code.py" with "./some_code.py" for website scripts?

35 views
Skip to first unread message

cseb...@gmail.com

unread,
Jun 6, 2022, 12:27:58 PM6/6/22
to Django users
How replace "./manage.py < some_code.py" with "./some_code.py" for website scripts?

There seem to be a number of imports needed to make the 2nd version work.

cs

Jason

unread,
Jun 6, 2022, 4:17:29 PM6/6/22
to Django users
Why?  what's the purpose behind this?

Muhammad Juwaini Abdul Rahman

unread,
Jun 6, 2022, 10:44:39 PM6/6/22
to django...@googlegroups.com
You can add the following lines in your script:

`
import django
sys.path.append('<your_django_directory>')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '<your_django_settings>')
django.setup()
`

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/72eaa595-0d6c-44d3-a612-4776b0624c6dn%40googlegroups.com.

cseb...@gmail.com

unread,
Jun 7, 2022, 3:29:42 PM6/7/22
to Django users
Thanks.  Works great!

cseb...@gmail.com

unread,
Jun 7, 2022, 3:31:56 PM6/7/22
to Django users
Don't you sometimes have housekeeping chores that are done by scripts?
Often those scripts want to access the ORM such as to update something
in the database.

I'm aware of notion of creating custom ./manage.py commands but
a standalone scripts seems easier no?

cs
Reply all
Reply to author
Forward
0 new messages