user1592380
user1592380

Reputation: 36277

Failed to load resource: net::ERR_NAME_NOT_RESOLVED

enter image description here

I have a django project and I am trying to load slides into the slick carousel (http://kenwheeler.github.io/slick/). I have the following:

<div class="your-class">
<div>your content</div>
<div><IMG src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSj2c33fdt1ugB8VBuE5V37wnmPoxWMknX9JnGycNiH2yr3BpDKVA"></div>
<div><IMG src="//static/img/slides/slide1.jpg"></div>
<div>your content</div>

You can see the file structure above. I have the carousel working but when I get to 'slide1' it gives the error in the title. How can I set the path properly?

Upvotes: 0

Views: 14356

Answers (2)

biomorgoth
biomorgoth

Reputation: 630

You are missing the hostname in the slide1.jpg url:

<div><IMG src="//static/img/slides/slide1.jpg"></div>

That way you are telling the browser that the image is in a hostname called "static", and that name is not being resolved.

If the image is hosted on the same server name that hosts your webpage, you should remove one of the first slashes, to convert your url from a protocol-relative URL to an absolute path:

<div><IMG src="/static/img/slides/slide1.jpg"></div>

On the other way, if you are truly using the protocol-relative URL, you need to define the server name in the url:

<div><IMG src="//www.yourserver.com/static/img/slides/slide1.jpg"></div>

--

NOTE: You should take a look at sgmart answer, because Django's staticfiles template support helps you creating the correct urls for your project static files.

Upvotes: 1

slackmart
slackmart

Reputation: 4934

First you need to set the STATICFILES_DIRS variable, in settings.py

STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'), )

Then requiere load staticfiles in your template:

{% load staticfiles %}

And finally use something like:

<div><IMG src="{% static 'img/slides/slide1.jpg' %}"></div>

Upvotes: 1

Related Questions