background-image not working(converting not local to local) - html

The Code:
style="background-image: url(wp-content/uploads/2018/03/example.jpg);"
Image is visible when doing this, but thats the whole reason im asking this question.
style="background-image: url(http://foo.com/wp-content/uploads/2018/03/example.jpg);"
wp-content IS the first folder in the path.
I've tried:
style="background-image: url('wp-content/uploads/2018/03/example.jpg');"
style="background-image: url(/wp-content/uploads/2018/03/example.jpg);"
style="background-image: url('../wp-content/uploads/2018/03/example.jpg');"
So the question is, why isn't the image not showing when the path is correct?
Solution Implementation:
style="background-image: url(insert_your_localhost/wp-content/uploads/2018/03/example.jpg);"

The path isn't correct.
Try this:
style="background-image: url('../wp-content/uploads/2018/03/example.jpg');"

The solution is to call image URL with site URL functions like wp_upload_dir, site_url, content_url
Veysel Xankisiyev have already submitted the solution.
Based on your examples, I'm trying to explain whats wrong with each method you're tried.
url('wp-content/uploads/2018/03/example.jpg')
In this case, browser will treat this image URL relative to your current URL. If you are on the home page, consider example.com, the resultant image URL will be example.com/wp-content/uploads/2018/03/example.jpg.
This will work as long as you were one home page, consider if you are in some other pages example.com/about/, the resultant image URL will be example.com/about/wp-content/uploads/2018/03/example.jpg. it is wrong one.
background-image: url(/wp-content/uploads/2018/03/example.jpg);
In this case, it will treat url relative to the domain/host always. Even if you are one homepage or in other pages, the resultant image url will be
example.com/wp-content/uploads/2018/03/example.jpg.
But as you said it didn't worked in your case means, your WordPress url path will be something like localhost/wordpress/ or example.com/wordpress or so. In such case, the resultant image URL will be localhost/wp-content/uploads/2018/03/example.jpg , wrong one.

Related

how to add background in Django2.0 using html or css

I want to add an image inside my django homepage, but I always cannot get the correct location of the image file I want(yellow high light)
The picture below are the thing I type so far:
https://i.stack.imgur.com/ecyQu.png
also in the same file
{% load static %}
body {
background-image: url('{% static "/bitcoin.jpg" %}');
}
Do I need static whenever I want to insert image in Django2.0? also,
I see some people open separate static file and some ppl put image inside the templete. I am confused where I should put? How can put the background image inside the html??
thank you so your answering!!!!
update ** this is what I have so far
enter image description here
updat2 ** the only refer to admin file only,
enter image description here
You can use inline CSS just for that case. You already have a .wrapper element, so if you want to put a static served image you'd do something like this:
<div class="wrapper" style="background-image: url('{% static 'default_page/bitcoin.jpg' %}');">
Your content here
</div>
If you want to use in your CSS files, just use the absolute path according to your static configuration. If you serve your static files using /static (that means, the path /static/default_page/bitcoin.jpg is correct and shows you the desired image), you can just put into the CSS something like:
body {
background-image: url('/static/default_page/bitcoin.jpg');
}
Hope that works!
EDIT:
As Thomas said, you've placed the image in the wrong folder (inside templates instead of on your static files folder). Refer to this to configure your project the right way.
You've placed your bitcoin.jpg in the same folder as your templates. Django serves all static file, such as pictures, from the static directory. Only templates go in the template directory. Create a directory called static inside your hompage app, create a directory inside that called default_page, and place your background image there. Restart the dev server, and your image should appear.

Vue img src concatenate variable and text

I'm trying to concatenate Vue variable with image URL, but the browser didn't show the picture. Could anyone tell me what's the matter with my coding?
I have tried as follow.
The picture didn't show in the browser.
<img :src="'../assets/'+item.picture">
If I wrote as below, the picture is shown.
<img src="../assets/6cb38c91115bcdf0c824124e4b5ecb71.jpeg">
Thank you very much!

Why do I get error `Failed to load resource` on the client?

I have this element in my index.cshtml page:
<section class="parallax parallax-2 padding-xxs" style="background-image: url('mySiteName/assets/images/shutterstoc/img1.jpg');">
<div>some content </div>
</section>
As you can see I have style attribute.
If I change style attribute to this:
style="background-image: url('~/assets/images/shutterstoc/img1.jpg');"
The background image is disappear and I get this error in web console:
Failed to load resource: the server responded with a status of 404 (Not Found) img1.jpg
**Update*
The path to the image is:
http://localhost/assets/images/shutterstoc/img1.jpg
As you can see the mySiteName is missing.
Update2:
I try this path:
<section class="parallax parallax-2 padding-xxs" style="background-image: url('./assets/images/img1.jpg')">
But still I get error above.
Why do I get error Failed to load resource and how to fix it?
The tilda sign ~ can be used in razor views to get the app root path. It will not work for css style sheet files.
When razor executes the view, if it finds the ~ , it will be converted to the app root base path.
Just use the path without the ~
background-image: url('./assets/images/shutterstoc/img1.jpg');
The image url is relative the stylesheet. So adjust the prefix . to ../ as needed depending on your location of the style sheet and the assets directory.
.someCssClass {
background-image: url('./assets/images/shutterstoc/img1.jpg');
}
Like i mentioned above, the image location is relative to the the location of the style sheet . If you hard code the style in the view/page, it will be relative to the page's url. So while the request yourSiteBaseUrl/ works , neither yourSiteBaseUrl/Home/ or yourSiteBaseUrl/Home/Index won't work, even though those 2 routes return the same action method and view/page. So i recommend not doing that.
Move the definition to the css file and use the correct relative path there tot he image location. It will then work for yourSiteBaseUrl/Home/Index and yourSiteBaseUrl/Home and yourSiteBaseUrl

ASP.NET MVC Img tag not loading image when loading path from database

I am attempting to make a photo gallery asp.net MVC website, and part of that involves the setting of the src to a local folder that contains images.
#model MyProj.Models.PhotoIndexViewModel
<div class="row" id="tableSearch">
#foreach (MyProj.Models.VideoModel photo in Model.PImgList)
{
<div class="col-sm-3 thumbnail">
#Html.DisplayFor(model => photo.Title)
<a href=#Url.Action("View", new { id = photo.Id })>
<img class="img-responsive"src="#Url.Content(photo.ThumbNailPrev)" alt=#photo.Id /></a>
#Html.HiddenFor(m => m.searchTerm)
#Html.Partial("_Tags", photo)
</div>
}
</div>
The ThumbNailPrev is "~/Pics/.jpg", which relates to a folder in the main part of the project. The issue is that the image does not appear. When I check the image using inspector is says it isn't found at /Pics/(photoid)/jpg. I don't understand why it is doing this, as my pics and the image itself are present at that location. I have also made sure to include the folder in my project, but it still doesn't seem to find the image.
UPDATE:
I just tried something and confirmed it is something to do with the way I'm calling the path from the database. As if I hard code the EXACT same string as the one in the database it works. The question now is why does that work?
For want of a letter..
I finally determined the problem, and it was a pretty dumb one. In code I am saving a jpEg image, but calling it via jpg. After changing the .jpg to .jpeg in the view everything works... If you are having a similar problem, check and make certain the file extension is correct.

ng-src not showing up for my img array

I have a simple image viewer webpage on gitpages but before I push the next group of images I want to condense all of my images into an array using angular.
The test I have made here uses only 4 photos that are in the same folder as every other file.(they are jpegs)
my js file is set up like this with a factory for the array and a controller.
angular.module('beamModule',[])
.factory('imageFactory', function(){
return {
getImages: function(){
return ['beam1.jpg','beam2.jpg','beam3.jpg','beam4.jpg'];
}
}
})
.controller('Photos', function(imageFactory){
this.images = imageFactory.getImages();
});
I don't think anything is wrong with this array but maybe I am overlooking something?
The HTML that I am using and the section that is giving me trouble when I check the developer tools is below.
<div class="imgcontainer" ng-controller="Photos as photosController">
<img ng-repeat="src in photosController.images"
ng-src="beamModule.js/{{images}}">
</div>
I am not sure if I am supposed to be using an ng-class attribute in the css or if there is something else that needs removed?
The developer tools are returning this value for each of the images (they are repeating just not showing)
<img ng-repeat="src in photosController.images" class="ng-scope">
Why is the ng-scope class being put in here and the ng-src is being removed?
EDIT FIXED
Ok to the person who answered so quickly and simply you are the real mvp here.
You said to change the ng-src="beamModule.js/{{images}}" to read {{src}} instead.
Once I tried this it still didnt work but then I checked the dev tools and noticed it was attempting to pull the files from the js file and not the actual file so I just changed it to this and now it works great! Thank you.
ng-src="{{src}}"
The ng-src attribute needed to point to the repeat instead of the js file.
ng-src="{{src}}"