I have a django project and I am trying to load slides into the slick carousel (/). I have the following:
<div class="your-class">
<div>your content</div>
<div><IMG src=":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?
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./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?
Share Improve this question asked Apr 27, 2015 at 2:44 user1592380user1592380 36.6k105 gold badges314 silver badges553 bronze badges2 Answers
Reset to default 1First 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>
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./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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744846870a4596891.html
评论列表(0条)