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 

36 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
  6. Excellent post. I was always checking this blog, and I’m impressed! Extremely useful info specially the last part, I care for such information a lot. I was exploring this particular info for a long time. Thanks to this blog my exploration has ended. video agentur

    ReplyDelete
  7. Very helpful
    I also have a projects in my website
    https://educationlinks.in

    ReplyDelete
  8. My spouse and I stumbled over here by a different web address and thought I might check things out. I like what I see so i am just following you. Look forward to checking out your web page again. webflow agency

    ReplyDelete
  9. Oh my goodness! a tremendous article dude. Thank you Nonetheless I'm experiencing difficulty with ur rss . Don know why Unable to subscribe to it. Is there anybody getting equivalent rss problem? Anybody who is aware of kindly respond. Thnkx webflow developers

    ReplyDelete
  10. Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!Thanks 统计代写

    ReplyDelete
  11. It is very difficult to find the movie of your choice particularly in horror movies genre. New-age online shopping portals are offering many titles under this category.

    0123movie

    ReplyDelete
  12. When it comes to movie distribution for an indie produced film the way it normally happens are independent producers and filmmakers take the risk making the movie without any guaranteed movie distribution deal in place.

    fmovies.co

    ReplyDelete
  13. Those type of indie film passion projects you can make once you've made it in the entertainment business at the studio level.123 movies

    ReplyDelete
  14. SoundCloud is the ultimate platform for musicians around the world to gain recognition for their tracks. soundcloud plays

    ReplyDelete
  15. Good site! I really love how it is simple on my eyes and the data are well written. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which must do the trick! Have a great day! ui ux design

    ReplyDelete
  16. Thank you for some other informative website. The place else may just I get that kind of information written in such a perfect method? I have a venture that I am simply now running on, and I’ve been at the glance out for such info. brand design firm

    ReplyDelete
  17. Sure, you can scour the internet and find scads of great topless or semi-nude and suggestive pix of Anderson, but that's not Scully, damnit! Bravo to Chris Carter and Gillian Anderson...uh...sort of.123movie

    ReplyDelete
  18. Also, most films don't get a theatrical release, and the funds are earned through other channels.

    0123movie

    ReplyDelete
  19. Many thanks taking a few minutes to discuss this unique, I find myself passionately with this and also adoration looking over on that problem. Just in case likely, since complete specialist knowledge, on earth would you feelings modernizing your main internet page along with other facts? This is very helpful for me. https://royalcbd.com/product/cbd-gummies-10mg/

    ReplyDelete
  20. He proves that film is a really powerful medium, and even though the formula conquers the motion picture industry, a filmmaker can still live up with a unique language that is challenging and refreshing - and this is such an achievement.0123movies

    ReplyDelete
  21. Additionally, it doesn’t matter how extremely you should be complete with treating a very platform, gradually you’ll discover an instance the places you should want to do a number instruct care; and as a consequence influenced by your real age but also bodybuilding, therfore the inches of one’s caravan it could be a awfully excessive pastime. motor movers web development firms

    ReplyDelete
  22. HOW I GOT MY LOAN FROM THIS GREAT COMPANY

    Hello my dear people, I am Linda McDonald, currently living in Austin Texas, USA. I am a widow at the moment with three kids and i was stuck in a financial situation in April 2018 and i needed to refinance and pay my bills. I tried seeking loans from various loan firms both private and corporate but never with success, and most banks declined my credit ,do not full prey to those hoodlums at there that call them self-money lender they are all scam , all they want is your money and you well not hear from them again they have done it to me twice before I met Mr. David Wilson the most interesting part of it is that my loan was transfer to me within 74hours so I will advise you to contact Mr. David if you are interested in getting loan and you are sure you can pay him back on time you can contact him via email……… (davidwilsonloancompany4@gmail.com) No credit check, no cosigner with just 2% interest rate and better repayment plans and schedule if you must contact any firm with reference to securing a loan without collateral then contact Mr. David Wilson today for your loan

    They offer all kind of categories of loan they

    Short term loan (5_10years)
    Long term loan (20_40)
    Media term loan (10_20)
    They offer loan like
    Home loan............., Business loan........ Debt loan.......
    Student loan.........., Business startup loan
    Business loan......., Company loan.............. etc
    Email..........( davidwilsonloancompany4@gmail.com)
    When it comes to financial crisis and loan then David Wilson loan financial is the place to go please just tell him I Mrs. Linda McDonald direct you Good Luck.......................

    ReplyDelete
  23. Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. seorango

    ReplyDelete
  24. Hello I found the Free Simple Shopping Icons Download | Design, Tech and Internet post very interesting therefore I’ve included our track-back for it on my own webpage, continue the great job:) web design agency new york

    ReplyDelete
  25. Come across back yard garden unusual periods of one’s Are generally Weight reduction and every one one may be important. One way state could possibly be substantial squandering through the diet. lose weight website design company nyc

    ReplyDelete
  26. There is greaser violence (not Grease greaser violence but like the Outsiders with a 90's humor twist), there is great Rockabilly music from Glen Glenn, Hasil Adkins and Johnny Reno!

    https://ww2.0123movie.net/

    ReplyDelete
  27. I used to be recommended this web site by my cousin. I’m no longer sure whether this put up is written via him as nobody else know such exact approximately my problem. You’re amazing! Thank you! web design agency new york

    ReplyDelete
  28. Immigration Lawyers… [...]here are some links to sites that we link to because we think they are worth visiting[...]… website design company nyc

    ReplyDelete
  29. This comment has been removed by the author.

    ReplyDelete
  30. Awesome blog, I’m going to spend more time researching this topic branding agencies in san francisco

    ReplyDelete
  31. This is a well-researched article which you have shared here about edit the uploaded image using external python. This is a very informative and useful article. This type of advice is not easy to find so, thanks for this information Watermark Edit Image Online

    ReplyDelete
  32. What a lovely blog page. I will certainly be back again. Please keep writing! branding sf

    ReplyDelete
  33. I like this blog so much, saved to bookmarks . ux san francisco

    ReplyDelete
  34. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info.
    website design long island

    ReplyDelete

Powered by Blogger.