Manoj Rawat
Manoj Rawat

Reputation: 31

How to access Models.py from external py script?

I want to integrate my existing code into django. How can I access models.py from external code.I tried putting it in the same application directory but it did not work.

Case Scenario: Having a web parsing code that takes data from the web and prints it. Here I am integrating it with django so as to save that data in the db and print it out in the web page. I'm trying the input to get from the webpage and when I hit submit it triggers the parsing code and gives output on the page.

I have the Django server up and running, created the apps (startapp), have the table created via models.py, have the urls.py setup. Here my question is how or where do I put my external code to make it trigger to access models .py, will it execute by itself when I start the server and hit the submit button ( i know i have to configure this one).

Upvotes: 0

Views: 44

Answers (1)

voodoo-burger
voodoo-burger

Reputation: 2153

There are a few lines you need to include in your script if you want to use Django in "standalone" mode. See the documentation here: https://docs.djangoproject.com/en/1.10/topics/settings/#calling-django-setup-is-required-for-standalone-django-usage .

Another option would be to turn your script into a Django management command which you would then call with manage.py.

Upvotes: 1

Related Questions