Wednesday, June 30, 2021

Sorting price and discount price (urgent)

I am facing a problem in including the discount_price into consideration when sorting price through the products. Kindly help me to do so. The below attached files are filters.py, views.py and  models.py.

Regards,
Aritra

class ProductFilter(django_filters.FilterSet):
    sort = OrderingFilter(
        choices=(
            ('price''Lowest to Highest'),
            ('-price''Highest to Lowest'),
            ),
        fields={
            'price''price',
            'price':'discount_price'
        },
    )
    price = RangeFilter()
    class Meta:
        model = Items
        fields = ['size''category']

class Product(ListView):
    model = Items
    paginate_by = 6
    template_name = 'products.html'
    ordering = ["-id"]

    def get_queryset(self):
        queryset = super().get_queryset()
        filter = ProductFilter(self.request.GETqueryset)
        return filter.qs

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        queryset = self.get_queryset()
        filter = ProductFilter(self.request.GETqueryset)
        context["filter"= filter
        return context
class Items(BaseModel):
    title = models.CharField(max_length=100, null=True, blank=True)
    price = models.FloatField(null=True, blank=True)
    discount_price = models.FloatField(max_length=100, blank=True, null=True)
    description = models.TextField(max_length=500)
    size = models.CharField(choices=SIZES, default=SIZES[0][0], max_length=10)
    category = models.CharField(choices=CATEGORY, default=CATEGORY[0][0], max_length=1)
    featured = models.BooleanField(default=False)
    availability = models.CharField(choices=AVAILABILITY, default=AVAILABILITY[0][0], max_length=1)
    image = ResizedImageField(upload_to="", null=True, blank=True)
    slug = models.SlugField(max_length=100)
    date_added = models.DateField(default=timezone.now)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFecadsUerZLP7gj7M23DLjytHQcuWc1ys2nqEcs_JNLKMc_Qg%40mail.gmail.com.

Re: In django you can either obtain a `csrftoken` from a cookie or the form can generate a nonce `csrftoken`. How does django validate both?

What if I can copy that cookie (samesite)  in developer tools from legitimate-site.com and create a new cookie for malicious-site.com using developer tools. After I do that I make a request. Will it be successful?
I think it would probably work. (This is not a security issue, though, since the user agrees. The problem is when malicious-site.com tries to do something to legitimate-site.com using the user's credentials without the user knowing.)

Antonis Christofides  +30-6979924665 (mobile)


On 01/07/2021 01.48, Patrice Chaula wrote:
What if I can copy that cookie (samesite)  in developer tools from legitimate-site.com and create a new cookie for malicious-site.com using developer tools. After I do that I make a request. Will it be successful?

On Wed, Jun 30, 2021, 3:43 PM Antonis Christofides <antonis@antonischristofides.com> wrote:

Django does not store csrftoken on the server.

Django provides the csrftoken in two places: 1) The cookie; 2) A hidden form field.

When the browser makes a POST request, then:

  1. It sends back the cookie anyway (that's what cookies do)
  2. It submits the csrftoken as a form field (or as the X-CSRFToken HTTP header in case of AJAX).

All Django does after that is verify that the token it receives with (2) is the same as the token it receives with (1).

Why this helps? Because the attack it is designed to mitigate is one where you visit malicious-site.com which contains the following:

<form method="post" target="https://legitimate-site.com">
    <input type="hidden" name="somename" value="somevalue">
    <!-- More hidden fields that, if submitted successfully to legitimate-site.com, will cause data loss or other problem -->
    <input type="submit" value="A message that pretends that when you click here something else is going to happen">
</form>

For this attack to succeed, malicious-site.com would need to specify a csrftoken as, say, a hidden form field (which is possible) AND provide the same token through a cookie. This is not possible. malicious-site.com can't set cookies of another site. The post request may indeed send a csrftoken as a cookie to legitimate-site.com, but this will be the csrftoken received the previous time the user visited legitimate-site.com. It will not be the same as the csrftoken sent as a hidden field, because malicious-site.com can't read cookies of another site, so it can't possibly read that cookie and set the hidden field to its value.

Antonis Christofides  +30-6979924665 (mobile)



On 30/06/2021 15.14, Patrice Chaula wrote:
In django you can either obtain a `csrftoken` from a cookie. Or the form can generate a nonce `csrftoken`. How does django validate both and where are they stored on the server. Are they stored as part of the session?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/83f3da74-ecbc-4197-9627-0c9ab9e8492fn%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7732c858-fd8c-53de-9a0f-99ae704ae4c6%40antonischristofides.com.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAE%3DG6DY1gG71vdqEUiax%3DQqfuqukC%3Dyi-qo9zKnwyra4i3ujDw%40mail.gmail.com.

Re: MODEL CONSTRAINT (based on two dates)

Short answer is that you can't; constraints cannot spans across JOINs.

You might be able to use database triggers to emulate though.

Le lundi 28 juin 2021 à 08:08:27 UTC-4, ngal...@gmail.com a écrit :

I have two models like this

How can I make models constraint based on the dates as shows on image??

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/87cda97d-9fd8-4264-bb37-8d466eec0cb4n%40googlegroups.com.

Re: In django you can either obtain a `csrftoken` from a cookie or the form can generate a nonce `csrftoken`. How does django validate both?

What if I can copy that cookie (samesite)  in developer tools from legitimate-site.com and create a new cookie for malicious-site.com using developer tools. After I do that I make a request. Will it be successful?

On Wed, Jun 30, 2021, 3:43 PM Antonis Christofides <antonis@antonischristofides.com> wrote:

Django does not store csrftoken on the server.

Django provides the csrftoken in two places: 1) The cookie; 2) A hidden form field.

When the browser makes a POST request, then:

  1. It sends back the cookie anyway (that's what cookies do)
  2. It submits the csrftoken as a form field (or as the X-CSRFToken HTTP header in case of AJAX).

All Django does after that is verify that the token it receives with (2) is the same as the token it receives with (1).

Why this helps? Because the attack it is designed to mitigate is one where you visit malicious-site.com which contains the following:

<form method="post" target="https://legitimate-site.com">
    <input type="hidden" name="somename" value="somevalue">
    <!-- More hidden fields that, if submitted successfully to legitimate-site.com, will cause data loss or other problem -->
    <input type="submit" value="A message that pretends that when you click here something else is going to happen">
</form>

For this attack to succeed, malicious-site.com would need to specify a csrftoken as, say, a hidden form field (which is possible) AND provide the same token through a cookie. This is not possible. malicious-site.com can't set cookies of another site. The post request may indeed send a csrftoken as a cookie to legitimate-site.com, but this will be the csrftoken received the previous time the user visited legitimate-site.com. It will not be the same as the csrftoken sent as a hidden field, because malicious-site.com can't read cookies of another site, so it can't possibly read that cookie and set the hidden field to its value.

Antonis Christofides  +30-6979924665 (mobile)



On 30/06/2021 15.14, Patrice Chaula wrote:
In django you can either obtain a `csrftoken` from a cookie. Or the form can generate a nonce `csrftoken`. How does django validate both and where are they stored on the server. Are they stored as part of the session?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/83f3da74-ecbc-4197-9627-0c9ab9e8492fn%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7732c858-fd8c-53de-9a0f-99ae704ae4c6%40antonischristofides.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAE%3DG6DY1gG71vdqEUiax%3DQqfuqukC%3Dyi-qo9zKnwyra4i3ujDw%40mail.gmail.com.

Re: when i am writing {%load static%} rather than getting exectuted it is getting displayed as simple text on htmloutput screen

load your static by putting space in between the percent and load and after static before  percent eg. {% load static %}.

On Wed, Jun 30, 2021, 2:56 PM pritam bhutada <pritambhutada5@gmail.com wrote:
try --->  {% load staticfiles %}

On Wednesday, June 30, 2021 at 9:47:46 AM UTC+5:30 ujjwal...@gmail.com wrote:
Dear all I am facing one problem.
When I am writing {%load static%} rather than getting executed it is getting displayed as simple text on the HTML output screen

Please provide me the solution.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8ba41bbd-6a9e-4d79-936e-e9ff7ce53dafn%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAP%2BiQEaMoeOxuQdxwg-9y%3D4heq8XCBgdvv1AOM%3DYu7K8bzb8_w%40mail.gmail.com.

return json value as char/text instead of json

I'm using Concat of some annotated json fields (from .values("data__somefield", "data__someotherfield")

The values are being returned as json, so the concatenation ends up with a hot mess of double quotes:
"somevalue" "someothervalue"
 
I can see in the query that Django is using the "->" operator to retrieve the value from the json which explains the double quotes.

Is there a way to encourage Django to retrieve as text (ie with the "->>" operator) - to prevent the double quotations?

Thanks

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/54dd60b9-0c19-469d-b3da-50ffdf2ed427n%40googlegroups.com.

Re: when i am writing {%load static%} rather than getting exectuted it is getting displayed as simple text on htmloutput screen

try --->  {% load staticfiles %}

On Wednesday, June 30, 2021 at 9:47:46 AM UTC+5:30 ujjwal...@gmail.com wrote:
Dear all I am facing one problem.
When I am writing {%load static%} rather than getting executed it is getting displayed as simple text on the HTML output screen

Please provide me the solution.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8ba41bbd-6a9e-4d79-936e-e9ff7ce53dafn%40googlegroups.com.

Re: In django you can either obtain a `csrftoken` from a cookie or the form can generate a nonce `csrftoken`. How does django validate both?

Django does not store csrftoken on the server.

Django provides the csrftoken in two places: 1) The cookie; 2) A hidden form field.

When the browser makes a POST request, then:

  1. It sends back the cookie anyway (that's what cookies do)
  2. It submits the csrftoken as a form field (or as the X-CSRFToken HTTP header in case of AJAX).

All Django does after that is verify that the token it receives with (2) is the same as the token it receives with (1).

Why this helps? Because the attack it is designed to mitigate is one where you visit malicious-site.com which contains the following:

<form method="post" target="https://legitimate-site.com">
    <input type="hidden" name="somename" value="somevalue">
    <!-- More hidden fields that, if submitted successfully to legitimate-site.com, will cause data loss or other problem -->
    <input type="submit" value="A message that pretends that when you click here something else is going to happen">
</form>

For this attack to succeed, malicious-site.com would need to specify a csrftoken as, say, a hidden form field (which is possible) AND provide the same token through a cookie. This is not possible. malicious-site.com can't set cookies of another site. The post request may indeed send a csrftoken as a cookie to legitimate-site.com, but this will be the csrftoken received the previous time the user visited legitimate-site.com. It will not be the same as the csrftoken sent as a hidden field, because malicious-site.com can't read cookies of another site, so it can't possibly read that cookie and set the hidden field to its value.

Antonis Christofides  +30-6979924665 (mobile)



On 30/06/2021 15.14, Patrice Chaula wrote:
In django you can either obtain a `csrftoken` from a cookie. Or the form can generate a nonce `csrftoken`. How does django validate both and where are they stored on the server. Are they stored as part of the session?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/83f3da74-ecbc-4197-9627-0c9ab9e8492fn%40googlegroups.com.

In django you can either obtain a `csrftoken` from a cookie or the form can generate a nonce `csrftoken`. How does django validate both?

In django you can either obtain a `csrftoken` from a cookie. Or the form can generate a nonce `csrftoken`. How does django validate both and where are they stored on the server. Are they stored as part of the session?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/83f3da74-ecbc-4197-9627-0c9ab9e8492fn%40googlegroups.com.

Re: when i am writing {%load static%} rather than getting exectuted it is getting displayed as simple text on htmloutput screen

Please import os in the settings.py file

On Wed, 30 Jun, 2021, 1:02 pm UJJWAL AGRAWAL, <ujjwalgl.sgi@gmail.com> wrote:
Dear patel dhruvish

"""
Django settings for mypro project.

Generated by 'django-admin startproject' using Django 3.2.4.

For more information on this file, see

For the full list of settings and their values, see
"""

from pathlib import Path,os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-*36^7=gu7_i_c!v6yw8!li0=2kwo9u!8$lgqbznb0i^3p09%m$'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'Fotoxplor',
    'mypro',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'mypro.urls'

TEMPLATES = [
    {
        'BACKEND''django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR,'templates')],
        'APP_DIRS'True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'mypro.wsgi.application'


# Database

DATABASES = {
    'default': {
        'ENGINE''django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME''django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME''django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME''django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME''django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)

STATIC_URL = '/static/'
STATICFILES_DIRS =[
    os.path.join(BASE_DIR,'templates')
]
STATIC_ROOT = os.path.join(BASE_DIR,'components')

# Default primary key field type

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

On Wed, Jun 30, 2021 at 10:54 AM patel dhruvish <pateldhruvish612000@gmail.com> wrote:
You want to add {%load static%} at the top of the code....

On Wed, Jun 30, 2021, 09:58 patel dhruvish <pateldhruvish612000@gmail.com> wrote:
Do you add static code in setting.py and urls.py? Code is here....
 
Setting.py:-
Project  urls.py:-
Then load static file with format like:-
STATICFILES_DIRS = [      BASE_DIR / "static",      '/var/www/static/',  ]

Project  urls.py:-
from django.conf import settings  from django.conf.urls.static import static    urlpatterns = [      # ... the rest of your URLconf goes here ...  ] 
+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Or
 + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Then load static file with format like:-
{% load static %}  <img src="{% static 'my_app/example.jpg' %}" alt="My image">


On Wed, Jun 30, 2021, 09:47 UJJWAL AGRAWAL <ujjwalgl.sgi@gmail.com> wrote:
Dear all I am facing one problem.
When I am writing {%load static%} rather than getting executed it is getting displayed as simple text on the HTML output screen

Please provide me the solution.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALQ%3D5fyZPWiBGnY6VJB1_C6Rb1Ls4dfsGfTef%2BBSqi1BXKHtfw%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANMvxF2ddJb5aHrK%3D88RRm40mxThRrCfUYjJyPBqkDWCCTWGwg%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALQ%3D5fyRaoJWhNH5SrWsXi3cLr74jNyziOvc41%3DSdfDze-H9Ow%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKxD5EteokVGbxmpjN2hcF6-WpDbpq74aMyEqc4aW12udMyj5w%40mail.gmail.com.

Re: when i am writing {%load static%} rather than getting exectuted it is getting displayed as simple text on htmloutput screen

Dear patel DHRUVISH urls.py code is:


from django.urls import path

from . import views

urlpatterns = [
    path('',views.home, name='home'),
]


On Wed, Jun 30, 2021 at 1:01 PM UJJWAL AGRAWAL <ujjwalgl.sgi@gmail.com> wrote:
Dear patel dhruvish

"""
Django settings for mypro project.

Generated by 'django-admin startproject' using Django 3.2.4.

For more information on this file, see

For the full list of settings and their values, see
"""

from pathlib import Path,os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-*36^7=gu7_i_c!v6yw8!li0=2kwo9u!8$lgqbznb0i^3p09%m$'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'Fotoxplor',
    'mypro',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'mypro.urls'

TEMPLATES = [
    {
        'BACKEND''django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR,'templates')],
        'APP_DIRS'True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'mypro.wsgi.application'


# Database

DATABASES = {
    'default': {
        'ENGINE''django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME''django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME''django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME''django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME''django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)

STATIC_URL = '/static/'
STATICFILES_DIRS =[
    os.path.join(BASE_DIR,'templates')
]
STATIC_ROOT = os.path.join(BASE_DIR,'components')

# Default primary key field type

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

On Wed, Jun 30, 2021 at 10:54 AM patel dhruvish <pateldhruvish612000@gmail.com> wrote:
You want to add {%load static%} at the top of the code....

On Wed, Jun 30, 2021, 09:58 patel dhruvish <pateldhruvish612000@gmail.com> wrote:
Do you add static code in setting.py and urls.py? Code is here....
 
Setting.py:-
Project  urls.py:-
Then load static file with format like:-
STATICFILES_DIRS = [      BASE_DIR / "static",      '/var/www/static/',  ]

Project  urls.py:-
from django.conf import settings  from django.conf.urls.static import static    urlpatterns = [      # ... the rest of your URLconf goes here ...  ] 
+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Or
 + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Then load static file with format like:-
{% load static %}  <img src="{% static 'my_app/example.jpg' %}" alt="My image">


On Wed, Jun 30, 2021, 09:47 UJJWAL AGRAWAL <ujjwalgl.sgi@gmail.com> wrote:
Dear all I am facing one problem.
When I am writing {%load static%} rather than getting executed it is getting displayed as simple text on the HTML output screen

Please provide me the solution.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALQ%3D5fyZPWiBGnY6VJB1_C6Rb1Ls4dfsGfTef%2BBSqi1BXKHtfw%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANMvxF2ddJb5aHrK%3D88RRm40mxThRrCfUYjJyPBqkDWCCTWGwg%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALQ%3D5fxhCKf%2BvXnk47erHOBT3B2Cz-GAFYSQLb%3Dy1TgjSjChbg%40mail.gmail.com.

Re: when i am writing {%load static%} rather than getting exectuted it is getting displayed as simple text on htmloutput screen

Dear patel dhruvish

"""
Django settings for mypro project.

Generated by 'django-admin startproject' using Django 3.2.4.

For more information on this file, see

For the full list of settings and their values, see
"""

from pathlib import Path,os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-*36^7=gu7_i_c!v6yw8!li0=2kwo9u!8$lgqbznb0i^3p09%m$'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'Fotoxplor',
    'mypro',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'mypro.urls'

TEMPLATES = [
    {
        'BACKEND''django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR,'templates')],
        'APP_DIRS'True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'mypro.wsgi.application'


# Database

DATABASES = {
    'default': {
        'ENGINE''django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME''django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME''django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME''django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME''django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)

STATIC_URL = '/static/'
STATICFILES_DIRS =[
    os.path.join(BASE_DIR,'templates')
]
STATIC_ROOT = os.path.join(BASE_DIR,'components')

# Default primary key field type

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

On Wed, Jun 30, 2021 at 10:54 AM patel dhruvish <pateldhruvish612000@gmail.com> wrote:
You want to add {%load static%} at the top of the code....

On Wed, Jun 30, 2021, 09:58 patel dhruvish <pateldhruvish612000@gmail.com> wrote:
Do you add static code in setting.py and urls.py? Code is here....
 
Setting.py:-
Project  urls.py:-
Then load static file with format like:-
STATICFILES_DIRS = [      BASE_DIR / "static",      '/var/www/static/',  ]

Project  urls.py:-
from django.conf import settings  from django.conf.urls.static import static    urlpatterns = [      # ... the rest of your URLconf goes here ...  ] 
+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Or
 + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Then load static file with format like:-
{% load static %}  <img src="{% static 'my_app/example.jpg' %}" alt="My image">


On Wed, Jun 30, 2021, 09:47 UJJWAL AGRAWAL <ujjwalgl.sgi@gmail.com> wrote:
Dear all I am facing one problem.
When I am writing {%load static%} rather than getting executed it is getting displayed as simple text on the HTML output screen

Please provide me the solution.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALQ%3D5fyZPWiBGnY6VJB1_C6Rb1Ls4dfsGfTef%2BBSqi1BXKHtfw%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANMvxF2ddJb5aHrK%3D88RRm40mxThRrCfUYjJyPBqkDWCCTWGwg%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALQ%3D5fyRaoJWhNH5SrWsXi3cLr74jNyziOvc41%3DSdfDze-H9Ow%40mail.gmail.com.

Re: when i am writing {%load static%} rather than getting exectuted it is getting displayed as simple text on htmloutput screen

Dear Patel Druvish ,
I have tried with that one 

Its showing such kind of error when trying to css file

Failed to load resource: the server responded with a status of 404 (Not Found)
extension.js:24 onMessage extension
ial.js:450 Clean the cache of the scraper (new onComplete event)
style.css'%%7D:1 Failed to load resource: the server responded with a status of 404 (Not Found)
The attempt to bind "/static/%7B%static%20'styles/style.css'%%7D" in the workspace failed as this URI is malformed.

HTML CODE{%load static%}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Fotoxplor</title>
    <link rel="stylesheet" type="text/css" href="{%static 'styles/style.css'%}">
</head>
<body>
    <h1 style="color: red;">Welcome to Fotoxplor</h1>
    <div class="box">
        <p>
            Fotoxplor
        </p>
    </div>
</body>
<header class="header">
    <div class="container">
        <div class="row">
            <div class="col">
                <div class="header_content d-flex flex-row align-items-center justify-content-start">
                    <div class="header_content_inner d-flex flex-row align-items-end justify-content-start">
                        <div class="logo"><a href="{%static 'home.html'%}">Fotoxplor</a></div>
                        <nav class="main_nav">
                            <ul class="d-flex flex-row align-items-start justify-content-start">
                                <li><a href="{%static 'aboutus.html'%}">About us</a></li>
                                <li><a href="">Services</a></li>
                                <li><a href="">News</a></li>
                                <li><a href="{%static 'contactus.html'%}">Contact</a></li>
                            </ul>
                        </nav>
                        <div class="header_phone ml-auto">Call us: 00-56 445 678 33</div>
                        <!-- Hamburger -->
                        <div class="hamburger ml-auto">
                            <i class="fa fa-bars" aria-hidden="true"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</header>
<div class="Phototype">
        <title>Photocateogry </title>
        <label for="browser">Choose your Photocateogry:</label>
        <input list="browsers" name="browser" id="browser">
        <datalist id="browsers">
          <option value="Nature">
          <option value="Animals">
          <option value="Food">
          <option value="Travel">
          <option value="Sports">
        </datalist>
        <input type="submit">
</div>


On Wed, Jun 30, 2021 at 9:58 AM patel dhruvish <pateldhruvish612000@gmail.com> wrote:
Do you add static code in setting.py and urls.py? Code is here....
 
Setting.py:-
Project  urls.py:-
Then load static file with format like:-
STATICFILES_DIRS = [      BASE_DIR / "static",      '/var/www/static/',  ]

Project  urls.py:-
from django.conf import settings  from django.conf.urls.static import static    urlpatterns = [      # ... the rest of your URLconf goes here ...  ] 
+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Or
 + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Then load static file with format like:-
{% load static %}  <img src="{% static 'my_app/example.jpg' %}" alt="My image">


On Wed, Jun 30, 2021, 09:47 UJJWAL AGRAWAL <ujjwalgl.sgi@gmail.com> wrote:
Dear all I am facing one problem.
When I am writing {%load static%} rather than getting executed it is getting displayed as simple text on the HTML output screen

Please provide me the solution.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALQ%3D5fyZPWiBGnY6VJB1_C6Rb1Ls4dfsGfTef%2BBSqi1BXKHtfw%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANMvxF0juEz51Pua5PRAR8uNjKPsSGVkZUnDYjTTtve7hfObag%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALQ%3D5fwh338p62K759MHec2AKP-_R4H%3DKN8ZdEs3axhopJL2GQ%40mail.gmail.com.