I am beginner and i dont know where i am doing mistake. i have seen these stack posts Return an image to the browser in python, cgi-bin , Return Image from python CGI using javascript and How to loading/show a picture in a Python CGI page but got no help.
Here is the code:
#!C:\Python27\python
text = """Content-type: text/html\n
<TITLE> CGI 101 </TITLE>
<H1>A SECOND CGI SCRIPT </H1>
<HR>
<P> HELLO,CGI WORLD!</P>
<img src="../imag000.jpg" width=101 height=64 border=0 alt="">
<HR>
"""
print (text)
and on browser it appears small box which is not showing image, like this:
Kindly help.
and folder which contains image is cgi. Kindly see picture:
Here is the best Solution:
<img src="http://localhost/imag000.jpg" width=101 height=64 border=0 alt="">
The HTML claims that the image is in the parent directory, but the server has it in the same directory. Either modify the HTML to match the current image location, or move the image to where the browser is requesting it from.
Related
I have the below HTML code that I am passing through a python script to send out an email. I am able to get the email however I am trying to have an image added to the body of the email but I see that the image does not get added to the email. I have the image saved to a variable called image and I am trying to call this variable. It just shows a greyed out area in the position where the image needs to be shown.
image = 'file.png'
f"""
<html>
<body style="background-color:#fafafa;">
<div class="row">
<div style="float:left;width: 20%;padding: 10px;">
</div>
div align="center" style="float:left;width: 60%;padding: 10px;">
<img src="cid:image" align="middle" width="253" height="68">
<br>
<h1 style="color:#9FA6B5;font-family:sans-serif;font-weight:200;text-align: center;">{name}</h1>
</div>
<div style="float:left;width: 20%;padding: 10px;">
</div>
</div>
</body>
</html>"""
You given the local path of the image, which can not be send to your email, you have to give path of the image from server image folder to show your image.
You have to upload your images to a server image then include the path into your src tag.
Here is a server i use to upload images for HTML email templates.
So I am having a bit of trouble inserting an image inside of a div container. At the top of my page I have a fixed navbar and, underneath the navbar, I have a jumbotron div with a div container with the name of the company as well as the tagline. Instead of there being a bg color for the div jumbotron/div container, I would like there to be an image instead that relates to the services and products that are being provided.
I am using Python Django to create the site and thus am using Jinja to implement static files such as images. Below is the code that I've used that does not work. I would like to be able to implement the image using this same Jinja method of static files rather than url(path to image here)... help?
<div>
<div class="jumbotron">
<div class="container" style="background-image:{% static 'company/img/familypic.jpg' %}">
<center><h2>Whatever Text Here</h2></center>
<center><h4>Whatever Tagline Here</h4></center>
</div>
</div>
</div>
It has to be url('{% static 'company/img/familypic.jpg' %}') for the background-image to show up.
Use
<div class="" style="background-image: url({{ static('company/img/familypic.jpg') }});">
I have code for sharing on pinterest in my site. The issue is that I can't get it to load a custom image.
Right now I have this where image_to_share is the path of the file:
<a href="https://www.pinterest.com/pin/create/button/
?url=http%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F
&media= {% static image_to_share %}
&description={{photo.description}}"
data-pin-do="buttonPin"
data-pin-config="above">
<img src="//assets.pinterest.com/images/pidgets/pin_it_button.png" />
</a>
When I inspect element in chrome I get the path for the image as :
<img src="http:// /static/assets/uploaded_files/1421974839_3_art2.jpg ">
However, it should look like this:
<img src="/static/assets/uploaded_files/1421974839_3_art2.jpg">
How do I remove the "http://" and the trailing white space so that my image gets rendered properly?
You can simply add your site's domain either hardcoded or with Django site
&media={{your_site_domain}}{% static image_to_share %}
your_site_domain can be example.com e.g.
More on Django sites: https://docs.djangoproject.com/en/1.7/ref/contrib/sites/#django.contrib.sites.models.Site.domain
I am trying to display images inline in Djano while sending HTML Email. I have the HTML Email working. But the images are displayed as an attachment, i followed the steps in https://www.vlent.nl/weblog/2014/01/15/sending-emails-with-embedded-images-in-django/ to display image as attachment. Which i do not want. I want the image to be displayed inline.
In my Django Template i have :
<img src="/static/url/location/image.png" />
The urls.py has the right setting. When i go to :
http://localhost:8000/static/url/location/image.png
i can see the image clearly.
When the email is sent, the image is not displayed and i do not know why. Any help is kindly appreciated.
I am using Django 1.6.2 btw.
EDIT: Implemented the suggestions given below about using Absolute URL.
I did try the absolute URL. Weird part is : When i used a absolute url of some other site, For ex:
<img src="google.com/images/srpr/logo11w.png"; />
the images are displayed inline. When i use the absolute url location of image on my local server, the image is not displayed :-(. Not sure what else i am missing.
You probably need an absolute url to the image on a server. Cannot reference relative images in an email as far as I know.
You could do this for an absolute url to the current host:
<img src="{{ request.get_host }}/static/url/location/image.png" />
You could probably benefit from using the {% static %} tag as well, (if you have static files configured correctly) like this:
<img src="{{ request.get_host }}{% static 'url/location/image.png' %}" />
I want to download a couple songs off of http://www.youtube-mp3.org/. I'm using urllib2 and BeautifulSoup.
The problem is that when I urllib2 open the site with my video ID plugged in, http://www.youtube-mp3.org/?c#v=lV7r8PiuecQ, I get the site but they are tricky about it and load the info after the initial pageload with some js ajax stuff. So when I try to scrape the url of the download link, literally isn't on the page because it hasn't been loaded.
Anyone know how I can maybe trigger this js loader in my python script, or something?
Here is the relevant empty html BEFORE the content that I want is loaded into it.
<div id="link_box" style="display:none">
<div id="link_box_title" style="font-weight:bold; text-decoration:underline">
</div>
<div class="row">
<div id="link_box_bb_code_title" style="font-weight:bold">
</div>
<input type="text" id="BBCodeLink" onclick="sAll(this)" />
</div>
<div class="row">
<div id="link_box_html_code_title" style="font-weight:bold">
</div>
<input type="text" id="HTMLLink" onclick="sAll(this)" />
</div>
<div class="row">
<div id="link_box_direct_code_title" style="font-weight:bold">
</div>
<input type="text" id="DirectLink" onclick="sAll(this)" />
</div>
</div>
<div id="v-ads">
</div>
<div id="dl_link">
</div>
<div id="progress">
</div>
<div id="loader">
<img src="ajax-loader-b.gif" alt="loading.." width="16" height="11" />
</div>
</div>
<div class="clear">
</div>
</div>
The API is JSON-based, so the contents of the html files won't give you any clue on where to find the files. A good idea when exploring web services like this one, is to open the Network tab in Chrome's developer tools and see what pages it loads when interacting with the page. That exercise showed me that two urls in particular seem interesting:
http://www.youtube-mp3.org/api/pushItem/?item=http%3A//www.youtube.com/watch%3Fv%3DKMU0tzLwhbE&xy=trve&r=1314700829128
http://www.youtube-mp3.org/api/itemInfo/?video_id=KMU0tzLwhbE&adloc=&r=1314700829314
The first url appears to be queuing a file for processing, the second to get the status of the processing job.
The second url takes a video_id GET parameter that is the id for the video on youtube (http://www.youtube.com/watch?v=KMU0tzLwhbE) and returns the status of the decoding job. The second and third seem irrelevant for this purpose which you can verify by test loading the url with and without the extra parameters.
The content of the page is:
info = { "title" : "Developers",
"image" : "http://i4.ytimg.com/vi/KMU0tzLwhbE/default.jpg",
"length" : "3", "status" : "serving", "progress_speed" : "",
"progress" : "", "ads" : "",
"h" : "a0aa17294103c638fa7f5e0606f839d3" };
Which happens to be JSON data. The interesting bit in this is "a0aa17294103c638fa7f5e0606f839d3" which looks like a hash that the web service use to refer to the decoded mp3 file. Also check out how the download link on the front page looks:
http://www.youtube-mp3.org/get?video_id=KMU0tzLwhbE&h=a0aa17294103c638fa7f5e0606f839d3
Now we have all the missing pieces of the puzzle together. First, we take the url of a youtube video (http://www.youtube.com/watch?v=iKP7DZmqdbU) url quote it and feed it to the api using this url:
http://www.youtube-mp3.org/api/pushItem/?item=http%3A//www.youtube.com/watch%3Fv%3DiKP7DZmqdbU&xy=trve
Then, wait a few moments until the decoding job is done:
http://www.youtube-mp3.org/api/itemInfo/?video_id=iKP7DZmqdbU
Take the hash found in the info url to construct the download url:
http://www.youtube-mp3.org/get?video_id=iKP7DZmqdbU&h=2e4b61b6ddc8bf83f5a0e4e4ee0635bb
Note that it is possible that the web master of the site does not want to be scraped and will take counter measures if people starts to (in the webmasters eyes) abuse the site. For example it seem to use referer protection so clicking the links in this post won't work, you have to copy them and load them in a new browser window.
Test code:
from re import findall
from time import sleep
from urllib import urlopen, quote
yt_code = 'gijypDkEqUA'
yt_url = 'http://www.youtube.com/watch?v=%s' % yt_code
push_url_fmt = 'http://www.youtube-mp3.org/api/pushItem/?item=%s&xy=trve'
info_url_fmt = 'http://www.youtube-mp3.org/api/itemInfo/?video_id=%s'
download_url_fmt = 'http://www.youtube-mp3.org/get?video_id=%s&h=%s'
push_url = push_url_fmt % quote(yt_url)
data = urlopen(push_url).read()
sleep(10)
info_url = info_url_fmt % yt_code
data = urlopen(info_url).read()
res = findall('"h" : "([^"]*)"', data)
download_url = download_url_fmt % (yt_code, res[0])
print 'Download here:', download_url
You could use selenium to interact with the js stuff and then combine it with BeautifulSoup or do everything with selenium, just as you prefer.
http://seleniumhq.org/
Selenium is a tool for browser automatization and has bindings for a few languages including Python. It takes a running instance of Firefox/IE/Chrome and let's you script it (I suggest using the selenium webdriver for this simple problem, not the whole selenium server).
You're going to have to work through http://www.youtube-mp3.org/client.js and figure out the exact information that is being passed around, this could allow you to post a request, parse the response and download from the correct scraped url.