简体   繁体   中英

DJANGO: executing other .py program from views.py

I've xmlparser.py. This .py parses a local XML file and then create/update objects from models SQLITE3 database.

This xmlparser.py file is in the same folder as views.py. Well, I wanna "execute" xmlparser.py (which update my db) and then get in views.py database objects updated for HttpResponse.

How could I do that?

I guess whatever you do in xmlparser.py is done with classes and functions. you should be able to import it and use those methods in the current python file.

In views.py:

import xmlparser

Then just use it as other python modules. Eg

xmlparser.your_method

You can execute anything on the OS with:

from subprocess import call
call(["python","xmlparser.py"])

Also look at the second answer here:

using python subprocess call to invoke python script

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM