Issue
Things I have done:
1.base template i have provide {% load static %}
<!DOCTYPE html>
{% load static %}
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="apple-touch-icon" sizes="76x76" href="/static/assets/img/apple-icon.png" >
<link rel="icon" type="image/png" href="{% static 'assets/img/favicon.png' %}" >
<title>
Al Amal Jewellery - {% block title %}{% endblock %}
</title>
<!-- Fonts and icons -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700" rel="stylesheet" />
<!-- Nucleo Icons -->
<link href="{% static "assets/css/nucleo-icons.css" %}" rel="stylesheet" />
<!-- Font Awesome Icons -->
<script src="https://kit.fontawesome.com/42d5adcbca.js" crossorigin="anonymous"></script>
<!-- CSS Files -->
<link id="pagestyle" href="{% static "assets/css/soft-ui-dashboard.css?v=1.0.5" %}" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.13.1/jquery-ui.min.js" integrity="sha256-eTyxS0rkjpLEo16uXTS0uVCS4815lc40K2iVpWDvdSY=" crossorigin="anonymous"></script>
<!-- Specific CSS goes HERE -->
{% block stylesheets %}{% endblock stylesheets %}
</head>
<body class="{% block body_class %}{% endblock %}">
{% include "includes/sidebar.html" %}
<main class="main-content max-height-vh-full h-100">
{% include "includes/navigation.html" %}
{% block content %}{% endblock content %}
</main>
{% include "includes/fixed-plugin.html" %}
{% include "includes/scripts.html" %}
<!-- Specific JS goes HERE -->
{% block javascripts %}{% endblock javascripts %}
<script>
var win = navigator.platform.indexOf('Win') > -1;
if (win && document.querySelector('#sidenav-scrollbar')) {
var options = {
damping: '0.5'
}
Scrollbar.init(document.querySelector('#sidenav-scrollbar'), options);
}
</script>
</body>
</html>
- statics in setting.py based on Managing Static Files
"""
Django settings for mysite project.
Generated by 'django-admin startproject' using Django 4.1.
For more information on this file, see
https://docs.djangoproject.com/en/4.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""
import os, random, string
from pathlib import Path
from dotenv import load_dotenv
load_dotenv() # take environment variables from .env.
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY')
if not SECRET_KEY:
SECRET_KEY = ''.join(random.choice( string.ascii_lowercase ) for i in range( 32 ))
# Render Deployment Code
DEBUG = True
ALLOWED_HOSTS = ['127.0.0.1','localhost', '.ngrok.io', '.ngrok-free.app','alamalcrm.azurewebsites.net','aacrm.azurewebsites.net']
CSRF_TRUSTED_ORIGINS = [os.getenv('CSRF_TRUSTED_ORIGINS')]
if not CSRF_TRUSTED_ORIGINS:
CSRF_TRUSTED_ORIGINS = ['https://aacrm.azurewebsites.net/','https://alamalcrm.azurewebsites.net/']
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
"whitenoise.runserver_nostatic",
'django.contrib.staticfiles',
# 'widget_tweaks',
'home',
'sales',
'purchases',
'chitty',
'inventory',
'wholesaler',
'accounts',
'authentication',
'rest_framework',
'import_export',
'django_apscheduler',
# 'django_extensions',
'mathfilters',
'django_cleanup.apps.CleanupConfig',
'daimond',
# "debug_toolbar",
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
"whitenoise.middleware.WhiteNoiseMiddleware",
'django.contrib.sessions.middleware.SessionMiddleware',
# "debug_toolbar.middleware.DebugToolbarMiddleware",
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'mysite.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',
],
},
},
]
TEMPLATE_LOADERS = (
('django.template.loaders.cached.Loader', (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)),
)
# Redirect to home URL after login (Default redirects to /accounts/profile/)
LOGIN_REDIRECT_URL = 'home'
LOGOUT_REDIRECT_URL = "login"
WSGI_APPLICATION = 'mysite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
DB_ENGINE = os.getenv('DB_ENGINE' , None)
DB_USERNAME = os.getenv('DB_USERNAME' , None)
DB_PASS = os.getenv('DB_PASS' , None)
DB_HOST = os.getenv('DB_HOST' , None)
DB_PORT = os.getenv('DB_PORT' , None)
DB_NAME = os.getenv('DB_NAME' , None)
if DB_ENGINE and DB_NAME and DB_USERNAME:
DATABASES = {
'default': {
'ENGINE' : 'django.db.backends.' + DB_ENGINE,
'NAME' : DB_NAME,
'USER' : DB_USERNAME,
'PASSWORD': DB_PASS,
'HOST' : DB_HOST,
'PORT' : DB_PORT,
},
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'db.sqlite3',
}
}
REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
'rest_framework.renderers.BrowsableAPIRenderer',
'rest_framework_datatables.renderers.DatatablesRenderer',
'rest_framework.parsers.JSONParser',
'rest_framework.parsers.FormParser',
'rest_framework.parsers.MultiPartParser',
),
'DEFAULT_FILTER_BACKENDS': (
'rest_framework_datatables.filters.DatatablesFilterBackend',
),
'DEFAULT_PAGINATION_CLASS': 'rest_framework_datatables.pagination.DatatablesPageNumberPagination',
'PAGE_SIZE': 50,
}
# Password validation
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
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
# https://docs.djangoproject.com/en/4.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
DATE_FORMAT = ['%Y-%m-%d']
USE_L10N = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(SITE_ROOT, '..', 'static'),
)
# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# Format string for displaying run time timestamps in the Django admin site. The default
# just adds seconds to the standard Django format, which is useful for displaying the timestamps
# for jobs that are scheduled to run on intervals of less than one minute.
#
# See https://docs.djangoproject.com/en/dev/ref/settings/#datetime-format for format string
# syntax details.
APSCHEDULER_DATETIME_FORMAT = "N j, Y, f:s a"
# Maximum run time allowed for jobs that are triggered manually via the Django admin site, which
# prevents admin site HTTP requests from timing out.
#
# Longer running jobs should probably be handed over to a background task processing library
# that supports multiple background worker processes instead (e.g. Dramatiq, Celery, Django-RQ,
# etc. See: https://djangopackages.org/grids/g/workers-queues-tasks/ for popular options).
APSCHEDULER_RUN_NOW_TIMEOUT = 25 # Seconds
DATA_UPLOAD_MAX_NUMBER_FIELDS = 10240
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
# STORAGES = {
# # ...
# "staticfiles": {
# "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
# },
# }
# INTERNAL_IPS = [
# # ...
# "127.0.0.1",
# # ...
# ]
- my directory
- In my inventory.html I provided the
{% extends 'base/base.html' %}
{% block title %} {{page2}} {% endblock title %}
<!-- Specific CSS goes HERE -->
{% block stylesheets %}{% endblock stylesheets %}
{% block body_class %} g-sidenav-show bg-gray-100 {% endblock %}
{% block content %}
<div class="container-fluid py-4">
<div class="row">
<div class="col-12">
<div class="card">
<!-- Card header -->
<div class="card-header pb-0">
<div class="d-lg-flex">
<div>
<h5 class="mb-0">{{page2}}</h5>
</div>
<div class="ms-auto my-auto mt-lg-0 mt-4">
<div class="ms-auto my-auto">
<a href= {% url 'newinventory' %} class="btn bg-gradient-primary btn-sm mb-0" target="_blank">+ New Stock</a>
<button class="btn btn-outline-primary btn-sm export mb-0 mt-sm-0 mt-1" data-type="csv" type="button" name="button">Export</button>
</div>
</div>
</div>
</div>
<div class="card-body px-0 pb-0">
<div class="table-responsive" id="div_inventorytable">
<table class="table table-flush" id="inventorytable">
<thead class="thead-light">
<tr>
<th>Name</th>
<th>Karat</th>
<th>WT</th>
<th>SWT</th>
<th>PMC</th>
<th>barcode</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% for item in object_list %}
<tr id="item-{{ item.pk }}">
<td>
<div class="d-flex">
<img class="w-10 ms-3" src="{{item.PhotoDIR.url}}" alt="hoodie" loading="lazy">
<h6 class="ms-3 my-auto">{{ item.Name }} - {{ item.Location }}</h6>
</div>
</td>
<td>{{ item.K.Name }}</td>
<td>{{ item.NetWT }}</td>
<td>{{ item.SWT }}</td>
<td>{{ item.PMC }}</td>
<td>{{ item.Barcode }}</td>
<td>{{ item.Status }}</td>
</td>
<td class="text-sm">
<a href="{% url 'barcodeprintpage' pk=item.pk t='item' %}" target="_blank" data-bs-toggle="tooltip" data-bs-original-title="Barcode">
<i class="fas fa-barcode text-secondary"></i>
</a>
{% if request.user.is_superuser %}
<a href="{% url 'itemupdate' item.id %}" class="mx-3" data-bs-toggle="tooltip" data-bs-original-title="Edit product">
<i class="fas fa-user-edit text-secondary"></i>
</a>
<a href="#" data-bs-toggle="tooltip" data-bs-original-title="Delete product" onclick="deleteitem('{{item.id}}')">
<i class="fas fa-trash text-secondary text-secondary"></i>
</a>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock content %}
<!-- Specific JS goes HERE -->
{% block javascripts %}
<script src="{% static "assets/js/plugins/datatables.js" %}"></script>
<script src="{% static "js/inventory/inventorylist.js" %}"></script>
{% comment %} <script src="{% static "js/inventory/barcode.js"%}"></script> {% endcomment %}
{% endblock javascripts %}
My issues
-
‘static’, expected ‘endblock’. Did you forget to register or load this tag? (on the inventory.html )
-
“GET /static/assets/img/favicon.png HTTP/1.1” 304 0 (this is on the base html only and 304 means it was already loaded right? )
i am not sure where i made a mistake
Solution
I believe you need to add {% load static %} at the top of your template. This will load them. Let me know if it helps.
Answered By - andrewbyteforge
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.