Can't load image with html - python

I've been trying to upload an image in my webpage where i have multiple directories. I tried loading the image when the file was in the same directory as index.html. I tried loading the image when the file was in the directory templates and i even tried to make a directory images and upload it from there but nothing works. As you can see from the image, I copied the path and the relative path(i tried both) and put int "img src" but the image just won't load. The terminal says that it can't find the image due to a 404 error and gets me a link but when i click the yellow link I am able to see the picture. What else can i try?
codespace

try relocating your image where your html file is and changing the type of file

index.html resides in /templates and your relative path would lead to /templates/workspaces which obviously does not exist.
You can do something like
<img src="slika.jpg">
if the index.html and slika.jpg are in the same directory.

Related

How can I display and download an image which is located outside of the static folder?

I'm setting up a script and I want to display an image which is located outside of my static folder. My project is designed like this:
___folder
|__ image.png
|__ text.txt
___web
|__static
|__ css
|__ js
|__ app.py
At the moment, I just run my script app.py. I have managed to create a hyperlink to download my image from another folder using the file protocol with this:
Download <br>
This way works but I'm forced to right click on the hyperlink and paste it in a new window in order to download it. I'm looking for a way to just left click on it.
After that, I've tried to display this same image with:
<img src="file://///{{ image_path }}" style="width:100%;" alt="Image not found">
but it actually doesn't work even if the path works for the previous part.
I've obtained some errors, when I've inspected the page as:
Failed to load resource: the server responded with a status of 404 (NOT FOUND)
UPDATE 1
Is there a way to solve my issue by using mimetype here?
Any help or direction is highly appreciated. Thank you.
https://www.w3schools.com/tags/att_a_download.asp
Simply add the download attribute to your <a> tag, e.g.,
<a href="file://///{{ image_path }}" download="filename.png">
The ="filename.png" is optional, you can just have download with no paramaters.
This is a security exception built into Chrome. In the past you could override settings in Chrome like this.
Check other topic in Stack, I can link dozens where you can find by yourself some help. You could use an intermediary page that serves the network based files for example.
You can find some help here.

Odoo doesn't displays markdown images

I want to display a markdown(readme) file into an odoo view as a field, i'm using the parser mistune to parse the file into an html format; as a result, the text is displayed as expected, except for every images located in src/img folder for the odoo module structure.
(example of image: ![Capture](static/src/img/usecase.png))
I've tried with the html inspector and it says the image wasn't found, and when I hover it, the path is http://server-s551lb:8069/static/src/img/usecase.png and I find it weird because it's only the relative path to locate the image.
Any help or idea would be welcome:)
I've found by adding modulename/ before static from the relative path of the image :)

Setting my <img> source to a file path outside of flask static folder

I need to display some images and these image filepaths are outside of flask's static folder stored on on network folders.
<img src="{{ filepath }}"> # /some/external/network/folder/img.jpg
However this is not working and I get a broken image icon, however I can paste the image path into my browser and confirm its accessible. I need this application to be able to accept image sources from anywhere, so I can't update my static folder to the network folder. I also can't load the images to the server because there would be about 20,000+ photos.
Is there a way to get this to work?

Django doesn't show the CSS of my template

The problem is described in title. I have this template for a blog that I'm creating using Django.
When I open it normally, using double click over the HTML file, it looks like this:
But when I open it via url from the Django project, it looks like this
It only shows a green square (part of the css) but obviously can't open the css correctly.
Any idea to solve this?
In Django you don't open the HTML with double click on the file, you need to run the server first and open your site using the localhost (like you did in the second picture).
Judging by those images, are you sure you put the image in the static folder? In Django, the HTML files stays in the "templates" folder of your app and the css, javascript and images in the "static" folder.
If this answer doesn't help you, then you should post your code here, otherwise I can't find the problem.

pyramid static view and file upload

I created new directory via 'myimages' under static directory. And whenever user upload files, file get stores in that directory. Once file uploaded I can access that on html using '/static/myimages/imagename.png'. It works fine whenever I am uploading new image. But whenver I try to override image. It shows me old image only.
I manually check in directory. It has new image, but still when I try to access that via browser, it gives me old image.
This sounds like your browser is caching the images. Try setting the cache_max_age=0 on your add_static_view, or viewing the page in your browser's incognito mode where it'll use a different cache.

Categories