Interfacing Django Project with Python Script

48 views
Skip to first unread message

Jake Rudolph

unread,
Jul 16, 2015, 7:55:30 PM7/16/15
to django...@googlegroups.com
If I have a separate Python script that I want to interact with my Django project, how do I set them up to communicate?

ADEWALE ADISA

unread,
Jul 16, 2015, 8:06:36 PM7/16/15
to django...@googlegroups.com

U can just import the modules in the script file the way you import django modules.

On Jul 17, 2015 12:55 AM, "Jake Rudolph" <jidru...@gmail.com> wrote:
If I have a separate Python script that I want to interact with my Django project, how do I set them up to communicate?

--
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 post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c15b50ce-7083-453f-b087-e09c3c8a808f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Larry Martell

unread,
Jul 17, 2015, 8:12:51 AM7/17/15
to django...@googlegroups.com
On Thu, Jul 16, 2015 at 7:44 PM, Jake Rudolph <jidru...@gmail.com> wrote:
> If I have a separate Python script that I want to interact with my Django
> project, how do I set them up to communicate?

Not 100% sure what you mean. Do you mean you want to have a standalone
python script that uses the ORM? I do this all the time. Just import
what you need.

Jake Rudolph

unread,
Jul 17, 2015, 12:55:25 PM7/17/15
to django...@googlegroups.com
So basically I have my Django app that takes in information from a user to make new objects, and I need to send some of that information to a separate script that performs logic and such with that information. When certain events occur I need to send information from the script to the database.

Gergely Polonkai

unread,
Jul 17, 2015, 5:30:14 PM7/17/15
to django...@googlegroups.com

I think what you really need is a custom Django management command. You can take a look at the implementation of createsuperuser, it takes some input and creates a user based on this info.

--
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 post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

Andy Shapiro

unread,
Jul 18, 2015, 9:46:44 AM7/18/15
to django...@googlegroups.com
For a standalone script (and django 1.7+), you'll need to add this at the top of your script:

Larry Martell

unread,
Jul 18, 2015, 9:59:19 AM7/18/15
to django...@googlegroups.com
On Fri, Jul 17, 2015 at 12:55 PM, Jake Rudolph <jidru...@gmail.com> wrote:
>> On Friday, July 17, 2015 at 5:12:51 AM UTC-7, Larry....@gmail.com wrote:
>>
>> On Thu, Jul 16, 2015 at 7:44 PM, Jake Rudolph <jidru...@gmail.com> wrote:
>> > If I have a separate Python script that I want to interact with my
>> > Django
>> > project, how do I set them up to communicate?
>>
>> Not 100% sure what you mean. Do you mean you want to have a standalone
>> python script that uses the ORM? I do this all the time. Just import
>> what you need.

> So basically I have my Django app that takes in information from a user to
> make new objects, and I need to send some of that information to a separate
> script that performs logic and such with that information. When certain
> events occur I need to send information from the script to the database.

Invoke that script with an ajax call. I do that all the time. I have a
view function that get called by the ajax request and that runs a
script and returns results back to the browser.
Reply all
Reply to author
Forward
0 new messages