Need assistance in fixing SuspiciousFileOperation error in django2.0












0















It appears as if the uploaded images have broken links:



Main page Myshop



This is the actual error when the images are clicked:



enter image description here



I wanted to figure it out if i did something wrong on my list.html






{% block title %} {% if category %}{{ category.name }}{% else %}Products{% endif %} {% endblock %} {% block content %}
<div id="sidebar">
<h3>Categories</h3>
<ul>
<li {% if not category %}class="selected" {% endif %}>
<a href="{% url " shop:product_list " %}">All</a>
</li>
{% for c in categories %}
<li {% if category.slug==c .slug %}class="selected" {% endif %}>
<a href="{{ c.get_absolute_url }}">{{ c.name }}</a>
</li>
{% endfor %}
</ul>
</div>
<div id="main" class="product-list">
<h1>{% if category %}{{ category.name }}{% else %}Products {% endif %}</h1>
{% for product in products %}
<div class="item">
<a href="{{ product.get_absolute_url }}">
<img src="{% if product.image %}{{ product.image.url }}{% else %}{% static " img/no_image.png " %}{% endif %}">
</a>
<a href="{{ product.get_absolute_url }}">{{ product.name }}</a>
<br> R{{ product.price }}
</div>
{% endfor %}
</div>
{% endblock %}





My views are as follows:



list all the products or filter products by a given category



My models:



managing catergories and products










share|improve this question

























  • What's your media root path in your settings file? Did you use forward or backward slashes? I suspect there's nothing wrong with your views, html template etc, it's probably related to some changes related to os.path in Python 3.6.7 that isn't compatible with Django 2.

    – Borut
    Nov 24 '18 at 19:17













  • I used forward slashes and here are my settings: MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

    – Prince Ndlozi
    Nov 24 '18 at 20:21













  • Yeah, change them to backslashes or double backslashes and it should fix your problem.

    – Borut
    Nov 24 '18 at 21:44













  • I mean, MEDIA_ROOT forwardslash to double backslash . You can also delete it, I guess.

    – Borut
    Nov 24 '18 at 21:51













  • Borut, thank you so much, by removing the MEDIA_ROOT it works perfectly.

    – Prince Ndlozi
    Nov 24 '18 at 22:06
















0















It appears as if the uploaded images have broken links:



Main page Myshop



This is the actual error when the images are clicked:



enter image description here



I wanted to figure it out if i did something wrong on my list.html






{% block title %} {% if category %}{{ category.name }}{% else %}Products{% endif %} {% endblock %} {% block content %}
<div id="sidebar">
<h3>Categories</h3>
<ul>
<li {% if not category %}class="selected" {% endif %}>
<a href="{% url " shop:product_list " %}">All</a>
</li>
{% for c in categories %}
<li {% if category.slug==c .slug %}class="selected" {% endif %}>
<a href="{{ c.get_absolute_url }}">{{ c.name }}</a>
</li>
{% endfor %}
</ul>
</div>
<div id="main" class="product-list">
<h1>{% if category %}{{ category.name }}{% else %}Products {% endif %}</h1>
{% for product in products %}
<div class="item">
<a href="{{ product.get_absolute_url }}">
<img src="{% if product.image %}{{ product.image.url }}{% else %}{% static " img/no_image.png " %}{% endif %}">
</a>
<a href="{{ product.get_absolute_url }}">{{ product.name }}</a>
<br> R{{ product.price }}
</div>
{% endfor %}
</div>
{% endblock %}





My views are as follows:



list all the products or filter products by a given category



My models:



managing catergories and products










share|improve this question

























  • What's your media root path in your settings file? Did you use forward or backward slashes? I suspect there's nothing wrong with your views, html template etc, it's probably related to some changes related to os.path in Python 3.6.7 that isn't compatible with Django 2.

    – Borut
    Nov 24 '18 at 19:17













  • I used forward slashes and here are my settings: MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

    – Prince Ndlozi
    Nov 24 '18 at 20:21













  • Yeah, change them to backslashes or double backslashes and it should fix your problem.

    – Borut
    Nov 24 '18 at 21:44













  • I mean, MEDIA_ROOT forwardslash to double backslash . You can also delete it, I guess.

    – Borut
    Nov 24 '18 at 21:51













  • Borut, thank you so much, by removing the MEDIA_ROOT it works perfectly.

    – Prince Ndlozi
    Nov 24 '18 at 22:06














0












0








0








It appears as if the uploaded images have broken links:



Main page Myshop



This is the actual error when the images are clicked:



enter image description here



I wanted to figure it out if i did something wrong on my list.html






{% block title %} {% if category %}{{ category.name }}{% else %}Products{% endif %} {% endblock %} {% block content %}
<div id="sidebar">
<h3>Categories</h3>
<ul>
<li {% if not category %}class="selected" {% endif %}>
<a href="{% url " shop:product_list " %}">All</a>
</li>
{% for c in categories %}
<li {% if category.slug==c .slug %}class="selected" {% endif %}>
<a href="{{ c.get_absolute_url }}">{{ c.name }}</a>
</li>
{% endfor %}
</ul>
</div>
<div id="main" class="product-list">
<h1>{% if category %}{{ category.name }}{% else %}Products {% endif %}</h1>
{% for product in products %}
<div class="item">
<a href="{{ product.get_absolute_url }}">
<img src="{% if product.image %}{{ product.image.url }}{% else %}{% static " img/no_image.png " %}{% endif %}">
</a>
<a href="{{ product.get_absolute_url }}">{{ product.name }}</a>
<br> R{{ product.price }}
</div>
{% endfor %}
</div>
{% endblock %}





My views are as follows:



list all the products or filter products by a given category



My models:



managing catergories and products










share|improve this question
















It appears as if the uploaded images have broken links:



Main page Myshop



This is the actual error when the images are clicked:



enter image description here



I wanted to figure it out if i did something wrong on my list.html






{% block title %} {% if category %}{{ category.name }}{% else %}Products{% endif %} {% endblock %} {% block content %}
<div id="sidebar">
<h3>Categories</h3>
<ul>
<li {% if not category %}class="selected" {% endif %}>
<a href="{% url " shop:product_list " %}">All</a>
</li>
{% for c in categories %}
<li {% if category.slug==c .slug %}class="selected" {% endif %}>
<a href="{{ c.get_absolute_url }}">{{ c.name }}</a>
</li>
{% endfor %}
</ul>
</div>
<div id="main" class="product-list">
<h1>{% if category %}{{ category.name }}{% else %}Products {% endif %}</h1>
{% for product in products %}
<div class="item">
<a href="{{ product.get_absolute_url }}">
<img src="{% if product.image %}{{ product.image.url }}{% else %}{% static " img/no_image.png " %}{% endif %}">
</a>
<a href="{{ product.get_absolute_url }}">{{ product.name }}</a>
<br> R{{ product.price }}
</div>
{% endfor %}
</div>
{% endblock %}





My views are as follows:



list all the products or filter products by a given category



My models:



managing catergories and products






{% block title %} {% if category %}{{ category.name }}{% else %}Products{% endif %} {% endblock %} {% block content %}
<div id="sidebar">
<h3>Categories</h3>
<ul>
<li {% if not category %}class="selected" {% endif %}>
<a href="{% url " shop:product_list " %}">All</a>
</li>
{% for c in categories %}
<li {% if category.slug==c .slug %}class="selected" {% endif %}>
<a href="{{ c.get_absolute_url }}">{{ c.name }}</a>
</li>
{% endfor %}
</ul>
</div>
<div id="main" class="product-list">
<h1>{% if category %}{{ category.name }}{% else %}Products {% endif %}</h1>
{% for product in products %}
<div class="item">
<a href="{{ product.get_absolute_url }}">
<img src="{% if product.image %}{{ product.image.url }}{% else %}{% static " img/no_image.png " %}{% endif %}">
</a>
<a href="{{ product.get_absolute_url }}">{{ product.name }}</a>
<br> R{{ product.price }}
</div>
{% endfor %}
</div>
{% endblock %}





{% block title %} {% if category %}{{ category.name }}{% else %}Products{% endif %} {% endblock %} {% block content %}
<div id="sidebar">
<h3>Categories</h3>
<ul>
<li {% if not category %}class="selected" {% endif %}>
<a href="{% url " shop:product_list " %}">All</a>
</li>
{% for c in categories %}
<li {% if category.slug==c .slug %}class="selected" {% endif %}>
<a href="{{ c.get_absolute_url }}">{{ c.name }}</a>
</li>
{% endfor %}
</ul>
</div>
<div id="main" class="product-list">
<h1>{% if category %}{{ category.name }}{% else %}Products {% endif %}</h1>
{% for product in products %}
<div class="item">
<a href="{{ product.get_absolute_url }}">
<img src="{% if product.image %}{{ product.image.url }}{% else %}{% static " img/no_image.png " %}{% endif %}">
</a>
<a href="{{ product.get_absolute_url }}">{{ product.name }}</a>
<br> R{{ product.price }}
</div>
{% endfor %}
</div>
{% endblock %}






python django






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 23:49









Dave

2,20951525




2,20951525










asked Nov 24 '18 at 18:00









Prince NdloziPrince Ndlozi

13




13













  • What's your media root path in your settings file? Did you use forward or backward slashes? I suspect there's nothing wrong with your views, html template etc, it's probably related to some changes related to os.path in Python 3.6.7 that isn't compatible with Django 2.

    – Borut
    Nov 24 '18 at 19:17













  • I used forward slashes and here are my settings: MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

    – Prince Ndlozi
    Nov 24 '18 at 20:21













  • Yeah, change them to backslashes or double backslashes and it should fix your problem.

    – Borut
    Nov 24 '18 at 21:44













  • I mean, MEDIA_ROOT forwardslash to double backslash . You can also delete it, I guess.

    – Borut
    Nov 24 '18 at 21:51













  • Borut, thank you so much, by removing the MEDIA_ROOT it works perfectly.

    – Prince Ndlozi
    Nov 24 '18 at 22:06



















  • What's your media root path in your settings file? Did you use forward or backward slashes? I suspect there's nothing wrong with your views, html template etc, it's probably related to some changes related to os.path in Python 3.6.7 that isn't compatible with Django 2.

    – Borut
    Nov 24 '18 at 19:17













  • I used forward slashes and here are my settings: MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

    – Prince Ndlozi
    Nov 24 '18 at 20:21













  • Yeah, change them to backslashes or double backslashes and it should fix your problem.

    – Borut
    Nov 24 '18 at 21:44













  • I mean, MEDIA_ROOT forwardslash to double backslash . You can also delete it, I guess.

    – Borut
    Nov 24 '18 at 21:51













  • Borut, thank you so much, by removing the MEDIA_ROOT it works perfectly.

    – Prince Ndlozi
    Nov 24 '18 at 22:06

















What's your media root path in your settings file? Did you use forward or backward slashes? I suspect there's nothing wrong with your views, html template etc, it's probably related to some changes related to os.path in Python 3.6.7 that isn't compatible with Django 2.

– Borut
Nov 24 '18 at 19:17







What's your media root path in your settings file? Did you use forward or backward slashes? I suspect there's nothing wrong with your views, html template etc, it's probably related to some changes related to os.path in Python 3.6.7 that isn't compatible with Django 2.

– Borut
Nov 24 '18 at 19:17















I used forward slashes and here are my settings: MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

– Prince Ndlozi
Nov 24 '18 at 20:21







I used forward slashes and here are my settings: MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

– Prince Ndlozi
Nov 24 '18 at 20:21















Yeah, change them to backslashes or double backslashes and it should fix your problem.

– Borut
Nov 24 '18 at 21:44







Yeah, change them to backslashes or double backslashes and it should fix your problem.

– Borut
Nov 24 '18 at 21:44















I mean, MEDIA_ROOT forwardslash to double backslash . You can also delete it, I guess.

– Borut
Nov 24 '18 at 21:51







I mean, MEDIA_ROOT forwardslash to double backslash . You can also delete it, I guess.

– Borut
Nov 24 '18 at 21:51















Borut, thank you so much, by removing the MEDIA_ROOT it works perfectly.

– Prince Ndlozi
Nov 24 '18 at 22:06





Borut, thank you so much, by removing the MEDIA_ROOT it works perfectly.

– Prince Ndlozi
Nov 24 '18 at 22:06












1 Answer
1






active

oldest

votes


















0














The quoting on this section of code in your template is wrong:



     <img src="{% if product.image %} {{ product.image.url }} {% else %} 
{% static 'img/no_image.png' %}{% endif %}">


I don't believe you can have conditionals like {% if %} inside double quotes. Try this instead:



{% if product.image %}
<img src="{{ product.image.url }}">
{% else %}
<img src="{% static 'img/no_image.png' %}">
{% endif %}





share|improve this answer
























  • Hi John Gordon, thanks for the reply in answering my question, how ever i still get the same error when i changed my code to the above you just provided.

    – Prince Ndlozi
    Nov 24 '18 at 19:00











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460948%2fneed-assistance-in-fixing-suspiciousfileoperation-error-in-django2-0%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The quoting on this section of code in your template is wrong:



     <img src="{% if product.image %} {{ product.image.url }} {% else %} 
{% static 'img/no_image.png' %}{% endif %}">


I don't believe you can have conditionals like {% if %} inside double quotes. Try this instead:



{% if product.image %}
<img src="{{ product.image.url }}">
{% else %}
<img src="{% static 'img/no_image.png' %}">
{% endif %}





share|improve this answer
























  • Hi John Gordon, thanks for the reply in answering my question, how ever i still get the same error when i changed my code to the above you just provided.

    – Prince Ndlozi
    Nov 24 '18 at 19:00
















0














The quoting on this section of code in your template is wrong:



     <img src="{% if product.image %} {{ product.image.url }} {% else %} 
{% static 'img/no_image.png' %}{% endif %}">


I don't believe you can have conditionals like {% if %} inside double quotes. Try this instead:



{% if product.image %}
<img src="{{ product.image.url }}">
{% else %}
<img src="{% static 'img/no_image.png' %}">
{% endif %}





share|improve this answer
























  • Hi John Gordon, thanks for the reply in answering my question, how ever i still get the same error when i changed my code to the above you just provided.

    – Prince Ndlozi
    Nov 24 '18 at 19:00














0












0








0







The quoting on this section of code in your template is wrong:



     <img src="{% if product.image %} {{ product.image.url }} {% else %} 
{% static 'img/no_image.png' %}{% endif %}">


I don't believe you can have conditionals like {% if %} inside double quotes. Try this instead:



{% if product.image %}
<img src="{{ product.image.url }}">
{% else %}
<img src="{% static 'img/no_image.png' %}">
{% endif %}





share|improve this answer













The quoting on this section of code in your template is wrong:



     <img src="{% if product.image %} {{ product.image.url }} {% else %} 
{% static 'img/no_image.png' %}{% endif %}">


I don't believe you can have conditionals like {% if %} inside double quotes. Try this instead:



{% if product.image %}
<img src="{{ product.image.url }}">
{% else %}
<img src="{% static 'img/no_image.png' %}">
{% endif %}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '18 at 18:13









John GordonJohn Gordon

9,60051729




9,60051729













  • Hi John Gordon, thanks for the reply in answering my question, how ever i still get the same error when i changed my code to the above you just provided.

    – Prince Ndlozi
    Nov 24 '18 at 19:00



















  • Hi John Gordon, thanks for the reply in answering my question, how ever i still get the same error when i changed my code to the above you just provided.

    – Prince Ndlozi
    Nov 24 '18 at 19:00

















Hi John Gordon, thanks for the reply in answering my question, how ever i still get the same error when i changed my code to the above you just provided.

– Prince Ndlozi
Nov 24 '18 at 19:00





Hi John Gordon, thanks for the reply in answering my question, how ever i still get the same error when i changed my code to the above you just provided.

– Prince Ndlozi
Nov 24 '18 at 19:00


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53460948%2fneed-assistance-in-fixing-suspiciousfileoperation-error-in-django2-0%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks