Header Ads

Run Python script on clicking Html Button | Upload and Edit Image Show edited Image to Html Page

In this Part of Running Python script on clicking html button i will show you how to Upload a image using Html Form and Edit the uploaded image using External Python script & map the edited image back to Html Page.

Check out this video, code below follows the video to help

If you like videos like this consider donating $1, or simply turn off AdBlocker. Either helps me to continue making tutorials.


Transcript/ Cheat sheet:

Html Templates :

Home.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 %}
<br><br>
{% if raw_url or edit_url %}
<span>
RAW IMAGE:
<img src={{raw_url}} height=500 width=500>
PROCESSED IMAGE:
<img src={{edit_url}} height=500 width=500>
</span>
{% endif %}
<br><br>
<form action="/external/" method="post" enctype="multipart/form-data">
{% csrf_token %}
Input Text:
<input type="text" name="param" required><br><br>
<br><br>
<input type="file" name="image" required>
<br><br>
<input type="submit" value="Execute External Python Script">
</form>
</body>
</html>



Views.py =>


import requests from django.shortcuts import render
import sys
from subprocess import run,PIPE
from django.core.files.storage import FileSystemStorage
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')
image=request.FILES['image']
print("image is ",image)
fs=FileSystemStorage()
filename=fs.save(image.name,image)
fileurl=fs.open(filename)
templateurl=fs.url(filename)
print("file raw url",filename)
print("file full url", fileurl)
print("template url",templateurl)
out= run([sys.executable,'//mnt//e//work//button-python-click//html button external python script//test.py',inp],shell=False,stdout=PIPE)
image= run([sys.executable,'//mnt//e//work//button-python-click//html button external python script//image.py',str(fileurl),str(filename)],shell=False,stdout=PIPE)
print(out)
print(image.stdout)
return render(request,'home.html',{'data':out.stdout,'raw_url':templateurl,'edit_url':image.stdout})


Urls.py =>


from django.contrib import admin from django.conf.urls import url
from django.conf import settings
from django.conf.urls.static import static
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),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Settings.py =>
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '&!eli6&)nyb+c4s!b=9=p@&q6@85_@u39$p6+sk23@v0o1iyhs'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'buttonpython.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'buttonpython.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_URL = '/static/'

External Python Scripts : 

Image.py
import sys from PIL import Image
image_fullpath=sys.argv[1]
image_name=sys.argv[2]
img= Image.open(str(image_fullpath))
image_save_path=image_fullpath.replace(image_name,"temp.png")
img.rotate(90).convert("LA").save(image_save_path)
print("/media/temp.png")
Test.py

import datetime
import sys
time=datetime.datetime.now()
output="Hi %s welcome to Hackanons & time is %s" % (sys.argv[1],time)
print(output)
Get Whole Source Code Here 

7 comments:

  1. 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
    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. You guys have surpassed my expectations! James is seriously amazing and is doing everything to help my Fiancé and me, in1weeks my credit score went up 700 points and I can only imagine what is to come. Thank you for the excellent customer service and doing exactly what you all have set out to do! NO GIMMICKS OR BS with you guys.They carry out any kind of hacks You can reachout to them via Hackintechnology@gmail.com +16692252253

    ReplyDelete
  3. My ex ruined my credit due to his incessant extravagant spending spree, I found myself in a big mess. I talked to a credit repair company and I was told that it would take me non less than a year to fix my credit. I was devastated, that's a very long time which I can't cope with. I looked online and came across Credit Doctor's contact, hit him up and to my greatest surprise, my credit was repaired in 4 working days from 486 -810. I was so amazed and it didn't cost me too much really. I implore you to contact him on for all credit issues and hacking issues. No doubt that he's the best out there and your problems will be solved!
    HACKINTECHNOLOGY@GMAIL.COM
    +16692252253

    ReplyDelete


  4. I've been seeing posts and testimonials about BLANK ATM CARD but I never believed it, not until I tried it myself. It was on the 12th day of March. I was reading a post about places to visit in Slovakia when I saw this captivating post about how a Man described as Mr Harry changed his life with the help of a Blank Atm Card. I didn't believe it at first until I decided to reach him through the mail address attached to the post. To my greatest imagination, it was real. Right now am living up to a standard I never used to live before. Today might be your lucky day! Reach Mr Harry via email:(harrybrownn59@gmail.com) see you on the brighter side of life.

    ReplyDelete
  5. Get your credit cleaned with the help of a reliable hacker. He's tested and trusted. I had a very low credit score (around 520) and it was ruining my life. I needed help. I was very depressed because of it and had been trying to repair it but It just seems nothing was capable of getting my score raised quickly. I needed something done fast. I had read a lot of good things about this hacker online which gave me a go ahead to try him out. I almost gave up my search for a real hacker because I kept meeting fake hackers who are always after the money, I've been conned by them. Hackinvade  is not about the money but about attaining a good reputation at always satisfying his customers. This is my way of showing appreciation for a job well done on my credit report. Reach out to him for help at hackinvade |AT| gmail |DOT| com or his phone # 256-294-4701.  

    ReplyDelete

Powered by Blogger.