Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Access Models.py from external py script

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 50
    Answer it

    Hi, I am trying to integrate my existing code into django. How do i access models.py from my external code.I tried putting it in the same apps directory it did not work. Is there a way ? 

    My Case: I have a web parsing code that takes data from the web and prints it. I want to integrate it with django so as to save that data in the db and print it out in the web page. I want the input to come 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. 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)

 1 Answer(s)

  • You can write a django management command which can be run as 

    `python manage.py <command-name>`

    it can be kept at app_name > management > commands >  command_name.py

    It will have access to all your django app code models/ methods from views or any classes.

    Take the reference from Django-Custom-Command link.

    You can call the same method from your web browser clicking a button if it links to that method using views.

     

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: