Header Ads

Run External Python Script on Clicking Html Button Part 2

In this part I continue my tutorial on Running Python Script by Clicking HTML Button. Here I will create a HTML form and submit button & once a user clicks on HTML button, values from HTML Form will be passed to a External Python Script and Output of script will be Mapped to HTML Page.
Before continuing this tutorial i will suggest you to watch the Part 1 of this tutorial where we Configured the Python Django Part for Creating HTML Template.




All the Code from this Video:


Python Django Code : 


Views.py : 
from django.shortcuts import render import requests
import sys
from subprocess import run,PIPE
def button(request):
return render(request,'home.html')
def output(request):
data=requests.get("https://www.google.com/")
print(data.text)
data=data.text
return render(request,'home.html',{'data':data})
def external(request):
inp= request.POST.get('param')
out= run([sys.executable,'//mnt//e//work//djnago_testing//test.py',inp],shell=False,stdout=PIPE)
print(out)
return render(request,'home.html',{'data1':out.stdout})
Urls.py:
from django.conf.urls import url
from
django.contrib import admin
from . import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', views.button),
url(r'^output', views.output,name="script"),
url(r'^external', views.external),
]

Home.html :



<!DOCTYPE html>
<html>
<head>
<title>
Python button script
</title>
</head>
<body>
<button onclick="location.href='{% url 'script' %}'">Execute Script</button> <hr>
{% if data %}
{{data | safe}}
{% endif %}
<form action="/external/" method="post">
{% csrf_token %}
Input Text:
<input type="text" name="param" required><br><br>
{{data_external}}<br><br>
{{data1}}
<br><br>
<input type="submit" value="Execute External Python Script">
</form>
</body>
</html>

External Python Script :

import sys
import datetime
time=datetime.datetime.now()
output="Hi %s currentadfwffffdwadwd time is %s" % (sys.argv[1],time)
print(output)

6 comments:

  1. hey man i need your help urgent
    i do not want to give any input but just a button that will enable me to execute .py file and print the output it on webpage

    HTML CODE:


    --------------------------------------------------------------------------------------------------------------------------------------------------------
    URLS CODE :


    from django.contrib import admin
    from django.urls import path
    from . import views
    urlpatterns = [
    path('admin/', admin.site.urls),
    path('', views.button),
    path('output', views.output)
    ]
    ------------------------------------------------------------------------------------------------------------------------------------------------------------
    VIEWS CODE :


    from django.shortcuts import render
    import requests
    import sys
    from subprocess import run,PIPE

    def button(request):
    return render(request,'home.html')

    def output(request):
    out = run(sys.executable,['E://a.py'],shell=False,stdout=PIPE)
    print(out)
    return render(request,'home.html',{'data':out})

    ReplyDelete
    Replies
    1. ⚡️☑️MEET THE REAL HACKERS☑️⚡️

      It Tears me Up Whenever we receive complaints from Clients About Their Experience With the Hackers They Met Before They Heard about us.
      These Days There Are alot of Hackers Online, You Just Have to Be Careful about who you meet for help, because many people now don't know who to ask for help anymore but there's really an actual solution to that which I am giving you for free, Don't go for the incompetent ones which I know you understand what I'm saying like hackers using gmail, yahoomail and other cheaper email accounts that could be easily hacked ⚠️🚷, come to think of it, why the fuck would a REAL HACKER want to use a Mailing Service that brings out his vulnerabilities? ❌❌ ❌ so can you see they are really not who they say they're, they are just here to Rip people Off, You Can Always Identify Them With Their False Write Ups and False Testimonies Trying To Lure you Into their Arms.❌❌❌ and my advice really goes out to you looking for a Real Hacker that's a heads up so that you wouldn’t fall deep into their trap no more.🚷⚠️⚠️⚠️

      ☑️ COMPOSITE CYBER SECURITY SPECIALISTS is here to Provide you with The Best Hackers, So you can get saved from The Arms of the Fake Hackers❌❌

      ☑️We have Legit Hackers and Private investigators at your service. 💻 Every member of our team is well experienced in their various niches with Great Skills, Technical Hacking Strategies And Positive Online Reviews And Recommendations💻🛠

      ☑️We have Digital Forensic Specialists, Certified Ethical Hackers, Computer Engineers, Cyber Security Experts, Private investigators and more on our team. Some Of These Specialist Includes ⭐️ DAWID CZAGAN⭐️ JACK CABLE ⭐️ SEAN MELIA ⭐️ ARNE SWINNEN ⭐️And More.
      Some Of The Services we render includes:
      * Website hacking 💻
      * Facebook and social media hacking 📲
      * Database hacking, & Blog Cleaning🛠
      * Phone and Gadget Hacking 📲
      • CREDIT CARD MISHAPS 💳 💥
      * Clearing Of Criminal Records ❌
      * RECOVERY OF LOST FUNDS ON BINARY OPTIONS & CAPITAL INVESTMENTS💰
      * Location Tracking 📲
      and many More

      ☑️ Our Goal is to make your digital life secure, safe and hassle-free. All you Need To do is To Write us a Mail Then We’ll Assigned any of These Hackers To You Instantly.


      ☑️ CONTACT:
      ••• Email:
      composite.cybersecurity@protonmail.com

      🔘2020 © composite cybersecurity specialists
      🔘Want faster service? Contact us!
      🔘All Rights Reserved ®️

      Delete
  2. hey man i need your help urgent!
    if i using uwsgi +nginx + django
    it say unable to load configuration from test.py



    ReplyDelete
  3. Excellent and professional investigative services. I hired Mr FRED for a very private and difficult matter of hacking my husband's phone and he far exceeded my expectations. He helped me get some info such as whatsapp, facebook, text messages, call logs and even phone conversations that I needed for proof of his secretive affair. The first time we spoke, we had a very long phone consultation in which he gave me all my options that he could think of to resolve my case, and he even recommended I try other options before hiring him, which shows that he is honest. I decided to hire him and I am glad I did. He is a fantastic investigator and a great person; to all loyal partners out there if you have a dishonest partner don't hesitate to send him a mail Contact: CYBERAPPHACK@GMAIL.COM.

    ReplyDelete
  4. the argument is not getting passed to the python script

    ReplyDelete

Powered by Blogger.