how to use .py file function via html or css button from django template

13 views
Skip to first unread message

THIRUMALAIVASAN K

unread,
May 23, 2020, 7:34:36 AM5/23/20
to Django users
Hi,

 i have created a site for local use and i need to run some some python script  when i click the button , how to do that 


i am using on raspberry  to contoll something via dashboard , so i am used django to create a site but i can't ontroll the GPIO pin's via website button 



Vishesh Mangla

unread,
May 23, 2020, 8:26:36 AM5/23/20
to django...@googlegroups.com

You can create a .py file in the same location where your views.py file is.

Then to import any function from there in the views.py you can use,

from <module_name> import <function name>

I rather prefer to make a folder structure like templates/<appname> and static/<appname>

And name it backend/my_app

Then inside there I store all the .py files

Then in views I use

from .backend.my_app import module_name

Sent from Mail for Windows 10

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0f01c9a8-60fb-4597-9170-c896e18058c5%40googlegroups.com.

 

Reply all
Reply to author
Forward
0 new messages