Products don't show on my website

Hello,

I’m encountering an issue when attempting to display my products on custom pages. I’m using an API for this purpose. Interestingly, when I log in as an admin, I can view my products without any problem. However, if I’m not logged in, the products are not visible. Below is the script I’m currently using:

document.addEventListener('DOMContentLoaded', function() {
    var url = window.location.href;
    var groupName = url.split('/').pop(); 

    fetch('/api/method/frappe.client.get_list?doctype=Item&filters=[["Item","item_group","=","' + groupName + '"]]&fields=["name","item_name","description","standard_rate","image"]')
    .then(response => response.json())
    .then(data => {
        var items_html = '<div class="row">';
        data.message.forEach(function(item) {
            // items_html += '<div class="col-md-4">';
            items_html += '<div class="card">';
            items_html += '<img src="' + item.image + '" class="card-img-top" alt="' + item.item_name + '">';
            items_html += '<div class="card-body">';
            items_html += '<h5 class="card-title">' + item.item_name + '</h5>'; 
            items_html += '<p class="card-text">' + item.description + '</p>'; 
            items_html += '<p class="card-text">Prix: ' + item.standard_rate + ' €</p>'; 
            items_html += '<a href="/produits/' + groupName + '/' + item.name + '" class="btn btn-primary">Voir le produit</a>'; 
            items_html += '</div>'; 
            items_html += '</div>'; 
            // items_html += '</div>'; 
        });
        items_html += '</div>'; // Fermer la balise row
        document.getElementById('items-container').innerHTML = items_html;
    })
    .catch(error => console.error('Error fetching articles:', error));
});

Thank you to whoever will help me.

After searching further, I tried in Python and found this function ‘frappe.db.get_all()’. However, I also have a problem here that I don’t understand:

def generer_html_articles():
    doctype = "Pick List Item"

    filters = {
    }

    fields = ["item_name", "description"]

    articles = frappe.db.get_all(doctype, filters=filters, fields=fields)

    articles_html = "<ul>"
    for article in articles:
        articles_html += f"<li><strong>{article['item_name']}</strong>: {article['description']}</li>"
    articles_html += "</ul>"

    return articles_html

articles_html = generer_html_articles()```


Traceback (most recent call last):
  File "apps/frappe/frappe/website/serve.py", line 18, in get_response
    response = renderer_instance.render()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/website/page_renderers/document_page.py", line 43, in render
    html = self.get_html()
           ^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/website/utils.py", line 524, in cache_html_decorator
    html = func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/website/page_renderers/document_page.py", line 52, in get_html
    self.update_context()
  File "apps/frappe/frappe/website/page_renderers/document_page.py", line 67, in update_context
    ret = self.doc.get_context(self.context)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/website/doctype/web_page/web_page.py", line 81, in get_context
    safe_exec(self.context_script, None, _locals, script_filename=f"web page {self.name}")
  File "apps/frappe/frappe/utils/safe_exec.py", line 101, in safe_exec
    exec(
  File "<serverscript>: web_page_e_liquide", line 18, in <module>
  File "<serverscript>: web_page_e_liquide", line 14, in generer_html_articles
NameError: name '_inplacevar_' is not defined

Could someone help me, please? Thank you.

Up

I always got this problem:

Than, my function is whitelisted:


I found it in the file:
frappe/frappe/client.py

I really need help please. I’m stuck since 1 month…

When you attach/upload your images, make sure you mark them as public, not private. They will then be placed in the /public/files directory. This will ensure they are rendered irrespective of who is browsing your website.

You have to amend src=“’ + item.image + '” to the correct path to the public files which is “'files/ + item.image + '”.

Question: Why do you not rather build the page with a Jinja template?