I have a project named "Project", and a PDF file caled "file.pdf" located in Project/app/assets/file.pdf. I want to render the PDF on a page called "file.html", located in Project/app/views/static/file.html.
I wrote the following code, but all that displays is an empty white box.
<embed src="../../assets/file.pdf" width="500" height="375" type='application/pdf'>
I'm pretty sure my browser can't find the file. What could I be doing wrong?
UPDATE: I also tried it with an image, placed in app/assets/images/Image.png, like so:
<embed src="../../assets/images/Image.png" width="500" height="375" type='image/png'>
but that doesn't render either.
UPDATE 2: Output from console:
Started GET "/file" for 127.0.0.1 at 2016-02-21 04:48:27 -0600
Processing by StaticController#file as HTML
Rendered static/file.html.erb within layouts/application (63.8ms)
Completed 200 OK in 757ms (Views: 749.4ms | ActiveRecord: 0.0ms)
Started GET "/assets/application.self-e570ac372b74f676a029186250aeeba9bf7016bcd014314d103b5d18b3eb858e.css?body=1" for 127.0.0.1 at 2016-02-21 04:48:28 -0600
Started GET "/assets/pdf-8f705790d319666d8f804cf8809f4d74f036483049ef8c520646d6c98ebedc5f.png" for 127.0.0.1 at 2016-02-21 04:48:28 -0600
Started GET "/assets/Advanced_Reading_Sample.pdf" for 127.0.0.1 at 2016-02-21 04:48:28 -0600
In your controller write,
def file
pdf_filename = File.join(Rails.root, "/assets/file.pdf")
send_file(pdf_filename, :filename => pdf_filename, :disposition => 'inline', :type => "application/pdf")
end
Rename your file.html => file.html.erb and place it under views/controller_name/file.html.erb, also add route to this controller action.
In above setup when you access controller/file/ pdf will shown in the browser(inline).
Try this and see if it works
<iframe src="yourfile.pdf" style="width:100%; height:700px;" frameborder="0"></iframe>
Create folder called pdf (for example) in app/assets and put there your file.pdf then in app/views/static/file.html change src of embed tag to /assets/file.pdf. This should do the trick.
Try, This will help
Click To View
thanks
Mark SykOv
Well I have no idea why my app can't find the file. I just ended up using iframes and the absolute url of the file:
<iframe src="http://www.project.com/file.pdf" style="width:100%;height:100%;"><p>Your browser does not support iframes.</p></iframe>
And finally, the file renders.
Related
I am trying to understand how to render an html inside another html using iframe and flask
I have tried using the<iframe src="{% include 'status.html' %}" width="100%" height="100%" style="outline:none; border:none; top:5%;"></iframe> way however the server is having a weird Not Found error "GET /%3C!DOCTYPE%20html%3E%3Chtml%20lang= HTTP/1.1" 404
I have also tried using another method, as well <iframe src="{{ status }}" width="100%" height="100%" style="outline:none; border:none; top:5%;"></iframe> and in the flask
status_render = os.path.join(app.root_path, 'templates', 'status.html')
#app.route("/")
def main():
return render_template(
"index.html",
status=status_render
)
Using the second method I am getting this error "GET /home/dimitris/Documents/SmartHome/MobileApp/templates/status.html HTTP/1.1" 404 despite of the fact that the status.html does exist on the above path
I read online that it should be a a separate request which means another flask route, however I am not really sure that I am understanding how this should be implemented.
For security reasons, html files can only be rendered by calls from within the function of the flask application.
Include this code within your .py application:
#app.route('/show_status')
def show():
return render_template('status.html')
In your html file, render the file as follows:
<iframe src="{{ url_for('show_frame') }}"></iframe>
There is no need to pass arguments to the html index in the main () function:
#app.route("/")
def main():
return render_template("index.html")
Funcionou para mim.
Espero ter ajudado.
I am not sure but there is some problem is displaying any kind of static or predefined urls of html/image in flask.
In order to achieve the desired output, follow the below steps:
In the <iframe> tag, give a value that will be used as a route in app.py. For example, let say you need to display iframe in the index.html. Then create iframe tag in index.html as:
<iframe src="/statusRoute" height="200", width="500">
Now create a route with the same name in the app.py as:
#app.route('/statusRoute')
def showStatus():
return flask.render_template('status.html')
Ensure that the status.html is present inside the templates folder.
This would render the status.html inside an iframe of the index.html page.
I made an automation for a webpage which has frames, and I need to click on several menu links before returning to the maincontent to complete the tasks. This automation is run from Access-VBA. Here is a fragment of the HTML that shows the frame:
<frameset id="topFrameset">
<frameset id="BodyFrameset" cols="0,177,*">
<frame name="ButtonsFrame" id="ButtonsFrame" target="main" scrolling="NO" noresize="" src="MyMenu.action">
#document
<html>
<body>
<input type="hidden" name="listParentsId" value="[501, 502, 503]" id="listParentsId">
<div id="menu_container">
<div id="menu_1" onmouseover="MENU.ToolTipsCreate('501')">
<a onclick="MENU.showItems('501', '')">My Account</a>
<img id="img_501" src="/common/images/dropdown2_arrow.png" onclick="MENU.showItems('501', '')">
</div>
</div>
</body></html>
</frame>
</frameset>
</frameset>
I am using the SeleniumBasic v2.0.9.0 bindings for VBA. See Browser automation in Excel VBA using Selenium for install and tutorial.
I've tried webdriver.SwitchToFrame, among many other tests, all of them failed.
Dim driver As selenium.WebDriver
Set driver = New ChromeDriver
driver.Get (URL)
'Here goes the part of the code that logs in the page, it's irrelevant for this analysis...
driver.SwitchToFrame ("topFrameset") 'This line returns Error N°: 8 - NoSuchFrameError. Frame not be found. Identifier:topFrameset
Hope that someone could guide me to click the link or the img element inside "menu_1". Thanks in advance.
In 'EXAMPLE TEST 2', Can you comment this line driver.SwitchToDefaultContentand try it?
Why you switch to defaultcontent before switching to frame?
defaultContent –> Switch back to default page
Try other options as well: (In JAVA, we do.)
switchTo().frame(int) – Switch to a frame with its index
switchTo().frame(“name of the frame”) – Switch to a frame with its name
switchTo().frame (WebElement) – Switch to a frame with its web element location
After working a lot with this, I found the solution by myself.
I installed the app "SideeX" available at the Google Store. I then recorded the actions I needed to emulate with Selenium.
Then, I noticed that the frames whose names I described in the original question (topFrameset, BodyFrameset, ButtonsFrame) where recorded by SideeX through their indexes.
So I just had to perform the same actions with Selenium. In my case, for example, I had the following sequence of actions:
driver.SwitchToFrame 0
driver.SwitchToFrame 1
driver.FindElementById("img_501").Click
driver.SwitchToParentFrame
driver.SwitchToFrame 2
This is just my case, but the important thing that can be helpful for others with the same problem is to know that you can use SideeX to help you find the indexes of elements or sequence of actions needed to achieve your goal.
I am using Angular 5 in an attempt to display an image that I have sat in a file 2 directories up from where I have the HTML, however I simply get the blank image box and an error in the console of:
GET http://localhost:4200/logo.jpg 404 (Not Found)
I am attempting to output via the code:
<img src="../../logo.jpg">
I have tested by placing a placeholder.it image within the src which worked perfectly... For some reason this will not?
If you are using #angular/cli you'd need to place your images under /src/assets/ in line with the .angular-cli.json asset configuration. You can then just use the image directly such as:
<img src="assets/pa-logo.jpg">
You can create additional folders under "assets" property in .angular-cli.json for additional control/organization as necessary:
"assets": [
"assets",
"foobar",
"favicon.ico"
],
Usage after you placed pa-logo.jpg in the this hypothetical foobar folder:
<img src="foobar/pa-logo.jpg">
Hopefully that helps!
Iam creating an image link in cakephp using html tag, i have a problem with adding src path.
I tried
<a href="#today1" id="lnk3">
<img src="/iserprofiles/app/webroot/img/todaysallocation.png">Todays Allocation</a>
but image is not loaded. if anybody know please reply. i know that we can also create image link using cakephp, but i faced one problem
i u sed this code
<?php echo $this->Html->link($this->Html->image('todaysallocation.png',
array('width' => '200', 'height' => '45')) ,
'#today',array('escape' => false));?>
i dont want to use any controller or action as url, simply i just added '#today',
but my problem is i need to add one id for this. how can we done this????
Check in Your browser patch: localhost/iserprofiles/app/webroot/img/todaysallocation.png
, but i think the problem is in Your .htaccess file, because path to image will look like localhost/iserprofiles/img/todaysallocation.png
Hi im new in jsp/servlets, i have a basic question about relative or abselute path:
i have the following hierarchy, using netbeans:
Web Pages
| |-Status
| |-clientRequests.jsp
| |-index.jsp
| |-WEB-INF
| |-professional.jsp
index.jsp and the Status folder and WEB-INF folder in root path.
inside the Status folder we have the clientRequests.jsp file.
inside the WEB-INF folder we have the professional.jsp file.
in the index.jsp i have done dispacher to professional.jsp,
inside professional jsp i have <iframe src="Status/clientsRequests.jsp"></iframe>
inside the clientsRequests.jsp i have
<%
response.setHeader("Refresh", "5;url=../index.jsp");
%>
that means that every 5 sec will be refresh to the clientsRequests.jsp file, and then go to the "controller" which is index.jsp.
now what i wanted to be that every 5 min, only the iframe refreshed and not the hole page.
my problem: in the second refresh it gives me 404.
i tried to play with that and i did something ugly like:
String a = (String)session.getAttribute("nav");
if(a == null){
session.setAttribute("nav", "aaa");
response.setHeader("Refresh", "5;url=../index.jsp");
}else{
response.setHeader("Refresh", "5;url=index.jsp");
}
and its working, but i dont want wo leave that like this way...
do you have any suggestions?
thank you!
Somehow your response is setting header for the parent of the iframe too. Put the below line in the of clientsRequests.jsp.
<meta http-equiv="refresh" content="5">
one Alternative would be to move the clientRequests.jsp to the same level as index.jsp.
That way in your code you can always do this
response.setHeader("Refresh", "5;url=index.jsp");
One advantage is with this set up , the <iframe src="Status/clientsRequests.jsp"></iframe> can be added to any of the JSP pages in your application and there is no change/impact in the servlet code