running a python script with values from views.py in Django -
I wrote in another example Python in the views.py file that I wrote, but I do not know that How to do. See myname_first.get ('username') password = username.password.exe ('username') password = view_alarm_settings (request): if request.method == 'POST': username = Request.POST.get ('password' ) Alarm = Alarm.Objects. () [0]. Alarm_setting response = htprespacection (alarm, content_type = 'text / plain') response_a = execfile ('alarm_file_') return response_a
I'm trying to respond in alarm_file.py Anyone have to do this?
According to the comment, make the function in alarm_file.py and import it. Do the same to call alarm_file.py: will ensure that you can just run: Import and use only functions from the alarm_file in your view: Python alarm_file.py , use
if __name__ == '__main __': is an alarm_file.py. It will include the argument to run when called
python alarm_file.py . In addition, you can use
sys.argv to get the logic passed in the command line. For example:
import sys def do_something (val): # Some print val # return will return something if __name__ == '__main__': Try: arg = sys.argv [1] except index [arg]: arg = none return_value = dot_group (rgr)
Python alarm_file.py some_argument
import from alarm_file_work ... Reaction = HT Iarpispakshn (alarm, Kantent_prkar = "text / plain") Response_a = Do_something (response) back response_a
Comments
Post a Comment