Re: reg: Issue while rendering the page

2019-09-20 Thread Badal Raina
*{% load 'static' %}  *use  this and make sure that* image src* path in *jinja
tag* with *static* keyword

*e.g *

**
B. Raina


On Wed, 18 Sep 2019 at 01:00, 'Amitesh Sahay' via Django users <
django-users@googlegroups.com> wrote:

> Below is the snippet of my project tree::
>
> [image: Inline image]
>
>
> Regards,
> Amitesh Sahay
> *91-750 797 8619*
>
>
> On Wednesday, 18 September, 2019, 12:58:57 am IST, Amitesh Sahay <
> amitesh.sa...@yahoo.com> wrote:
>
>
> Hello Users,
>
> I am building an app called "SHOP". For some very wired reason I am
> getting below error:
> 
> ValueError at /shop/
>
> The 'image' attribute has no file associated with it.
>
> Request Method: GET
> Request URL: http://localhost:8000/shop/
> Django Version: 2.2.5
> Exception Type: ValueError
> Exception Value:
>
> The 'image' attribute has no file associated with it.
>
> Exception Location: 
> /home/amitesh/PycharmProjects/myvenv/lib/python3.6/site-packages/django/db/models/fields/files.py
> in _require_file, line 38
> Python Executable: /home/amitesh/PycharmProjects/myvenv/bin/python
> Python Version: 3.6.8
> Python Path:
>
> ['/home/amitesh/PycharmProjects/perfectcushion',
>  '/usr/lib/python36.zip',
>  '/usr/lib/python3.6',
>  '/usr/lib/python3.6/lib-dynload',
>  '/home/amitesh/PycharmProjects/myvenv/lib/python3.6/site-packages']
>
> Server time: Tue, 17 Sep 2019 18:59:22 +
>  
> When I see the debug page further I see that my base.html is complaining,
> below is the error:
> Error during template rendering
>
> In template
> /home/amitesh/PycharmProjects/perfectcushion/SHOP/templates/base.html,
> error at line *0*
> The 'image' attribute has no file associated with it.
> 1 {% load staticfiles %}
> 2 
> 3 
> 4 
> 5 
> 6 
> 7 {% block title %}{% endblock %}
> 8 
> 9 
>
>
> base.html
>
> {% load staticfiles %}
> 
> 
> 
> 
> 
> {% block title %}{% endblock %}
> 
> 
> 
> {% include 'header.html' %}
> {% include 'navbar.html' %}
> {% block content %}
> {% endblock %}
> 
> {% include 'footer.html' %}
>
> 
> 
>
> headers.html
>
> {% load staticfiles %}
> 
> 
> 
> 
> 
>
> navbar.html
>
> {% load staticfiles %}
> 
> 
> All Products
> Your Cart()
> 
> 
>
> category.html
>
> {% extends 'base.html' %}
> {% load staticfiles %}
> {%  block metadescription %}
> {% if category %}
> {{ category.description|truncatewords:125 }}
> {% else %}
> Welcome to the cushion store where you can buy comfy and awesome 
> cushions.
> {% endif %}
> {% endblock %}
>
> {% block title %}
> {% if category %}
> {{ category.name }} - Perfect Cushion Store
>  {% else %}
> See our Cushion Collection - Perfect Cushion Store
> {% endif %}
> {% endblock %}
>
> {% block content %}
> 
> {%  if category %}
> 
> 
> Our Product 
> Collection | {{ category.name }}
> 
> 
> {% endif %}
> 
> {% if category %}
> 
>
> 
> 
> 
> {{ category.name }}
> {{ category.description }}
> 
> {% else %}
> 
>  
>  
>  
> Our Products collection
> 
> Lorem Ipsum is simply dummy text of the printing and typesetting 
> industry. Lorem Ipsum has been the industry's standard dummy text 
> ever since the 1500s, when an unknown printer took a galley of 
> type and.
>  
> {% endif %}
> 
> 
> {% for product in products %}
> 
> 
> 
> 
> {{ product.name }}
> {{ product.price }}
> 
> 
> 
> {% endfor %}
> 
> 
> {% endblock %}
>
> SHOP/urls.py
>
> from django.urls import path
> from . import views
>
> app_name = 'shop'
>
> urlpatterns = [
> path('', views.allProdCat, name='allProdCat'),
> path('/', views.allProdCat, name='products_by_category'),
> ]
>
> project/urls.py
>
> from django.contrib import admin
> from django.urls import path, include
> from SHOP import views
> from django.conf import settings
> from django.conf.urls.static import static
>
> urlpatterns = [
> path('admin/', admin.site.urls),
> path('shop/', include('SHOP.urls')),
> ]
>
> # We need to map the static and the media URLS with the below settings
> if settings.DEBUG:
> urlpatterns += static(settings.STATIC_URL, 
> document_root=settings.STATIC_ROOT)
> urlpatterns += static(settings.MEDIA_URL, 
> document_root=settings.MEDIA_ROOT)
>
> views.py
>
> from django.shortcuts import render, get_object_or_404
> from .models import Category, Product
>
>
> def allProdCat(request, c_slug=None):
> c_p

Re: reg: Issue while rendering the page

2019-09-17 Thread 'Amitesh Sahay' via Django users
Below is the snippet of my project tree::





Regards,
Amitesh Sahay91-750 797 8619 

On Wednesday, 18 September, 2019, 12:58:57 am IST, Amitesh Sahay 
 wrote:  
 
 Hello Users, 
I am building an app called "SHOP". For some very wired reason I am getting 
below error:
ValueError at /shop/
The 'image' attribute has no file associated with it.
| Request Method: | GET |
| Request URL: | http://localhost:8000/shop/ |
| Django Version: | 2.2.5 |
| Exception Type: | ValueError |
| Exception Value: | The 'image' attribute has no file associated with it. |
| Exception Location: | 
/home/amitesh/PycharmProjects/myvenv/lib/python3.6/site-packages/django/db/models/fields/files.py
 in _require_file, line 38 |
| Python Executable: | /home/amitesh/PycharmProjects/myvenv/bin/python |
| Python Version: | 3.6.8 |
| Python Path: | ['/home/amitesh/PycharmProjects/perfectcushion',
 '/usr/lib/python36.zip',
 '/usr/lib/python3.6',
 '/usr/lib/python3.6/lib-dynload',
 '/home/amitesh/PycharmProjects/myvenv/lib/python3.6/site-packages'] |
| Server time: | Tue, 17 Sep 2019 18:59:22 + |

 When I see 
the debug page further I see that my base.html is complaining, below is the 
error:
Error during template rendering

In template 
/home/amitesh/PycharmProjects/perfectcushion/SHOP/templates/base.html, error at 
line 0

The 'image' attribute has no file associated with it.

| 1 | {% load staticfiles %} |
| 2 |  |
| 3 |  |
| 4 |  |
| 5 |   |
| 6 |   |
| 7 |  {% block title %}{% endblock %} |
| 8 |  |
| 9 |  |



base.html
{% load staticfiles %}





{% block title %}{% endblock %}



{% include 'header.html' %}
{% include 'navbar.html' %}
{% block content %}
{% endblock %}

{% include 'footer.html' %}


headers.html
{% load staticfiles %}




navbar.html
{% load staticfiles %}


All Products
Your Cart()


category.html
{% extends 'base.html' %}
{% load staticfiles %}
{%  block metadescription %}
{% if category %}
{{ category.description|truncatewords:125 }}
{% else %}
Welcome to the cushion store where you can buy comfy and awesome 
cushions.
{% endif %}
{% endblock %}

{% block title %}
{% if category %}
{{ category.name }} - Perfect Cushion Store
 {% else %}
See our Cushion Collection - Perfect Cushion Store
{% endif %}
{% endblock %}

{% block content %}

{%  if category %}


Our Product 
Collection | {{ category.name }}


{% endif %}

{% if category %}





{{ category.name }}
{{ category.description }}

{% else %}

 
 
 
Our Products collection

Lorem Ipsum is simply dummy text of the printing and typesetting 
industry. Lorem Ipsum has been the industry's standard dummy text 
ever since the 1500s, when an unknown printer took a galley of type 
and.
 
{% endif %}


{% for product in products %}




{{ product.name }}
{{ product.price }}



{% endfor %}


{% endblock %}SHOP/urls.py
from django.urls import path
from . import views

app_name = 'shop'

urlpatterns = [
path('', views.allProdCat, name='allProdCat'),
path('/', views.allProdCat, name='products_by_category'),
]project/urls.py
from django.contrib import admin
from django.urls import path, include
from SHOP import views
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
path('admin/', admin.site.urls),
path('shop/', include('SHOP.urls')),
]

# We need to map the static and the media URLS with the below settings
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, 
document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, 
document_root=settings.MEDIA_ROOT)views.py
from django.shortcuts import render, get_object_or_404
from .models import Category, Product


def allProdCat(request, c_slug=None):
c_page = None
products = None
if c_slug is not None:
c_page = get_object_or_404(Category, c_slug=c_slug)
products = Product.objects.filter(category=c_page, available=True)
else:
products = Product.objects.all().filter(available=True)
return render(request, 'shop/category.html', {'category': c_page, 
'products': products})Please help me figure out my mistake.



Regards,
Amitesh Sahay  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop r