css - 静态文件不能在cpanel上上传
问题描述
我收到错误消息,我的静态文件无法在我的 wep 应用程序中完全执行
这个应用程序在我的电脑上可以正常工作,但不能在 c 面板上运行
我在sharehost上,所以我不能使用nginex 如何解决这个问题
这是我的设置:
import os
from pytz import common_timezones
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'r&94@o%)q8s-=gmxw@8a9o5161%90&2jo$0*&a&57*5$rx)@ar'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ALLOWED_HOSTS = ["*"]
# Application definition
INSTALLED_APPS = [
#default
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
#local components
'omuser',
'ommessage',
'omformflow',
'omflow',
'omdashboard',
'omformmodel',
'omservice',
'ommission',
]
AUTH_USER_MODEL = 'omuser.OmUser'
LOGIN_REDIRECT_URL = '/home/'
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'omflow.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',
'django.template.context_processors.i18n',
'django.template.context_processors.static',
'django.template.context_processors.media',
],
},
},
]
WSGI_APPLICATION = 'omflow.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
# Password validation
# https://docs.djangoproject.com/en/2.2/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/2.2/topics/i18n/
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale'),
)
LANGUAGES = [
("en", "English"),("zh-hant", "Traditional_Chinese"),("zh-hans", "Simplified_Chinese"),("ja", "Japanese"),("ar","Arabic")
]
LANGUAGE_CODE = 'en'
#TIME_ZONE = 'Africa/Cairo'
TIME_ZONES = [(tz, tz) for tz in common_timezones]
DATE_FORMAT = '%Y-%m-%d'
DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S'
DATETIME_INPUT_FORMATS = '%Y-%m-%d %H:%M:%S'
USE_I18N = True
USE_L10N = False
# USE_TZ = True
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
# SESSION_COOKIE_AGE = 3600
MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads')
FILE_UPLOAD_TEMP_DIR = BASE_DIR
FILE_UPLOAD_MAX_MEMORY_SIZE = 52428800
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
STATIC_URL = '/static/'
# static url Mapping folder
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'staticfiles'),
#os.path.join(BASE_DIR, 'omuser', 'staticfiles'),
)
# staticfiles_dirs Mapping folder
#STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_ROOT = os.path.join(BASE_DIR, '..', 'static')
LOG_DIR = os.path.join(BASE_DIR, 'logs')
LOG_LEVEL = 'ERROR'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'simple': {
'format': '[%(asctime)s] - %(levelname)-8s - %(message)s',
'datefmt': DATETIME_FORMAT,
},
},
"filters": {
"infofilter": {
"()": "omflow.syscom.default_logger.LowLevelFilter",
"level": 20
},
"warnfilter": {
"()": "omflow.syscom.default_logger.HighLevelFilter",
"level": 30
}
},
'handlers': {
'consoleInfo': {
'class': 'logging.StreamHandler',
'formatter': 'simple',
"filters": ["infofilter"]
},
'consoleError': {
'class': 'logging.StreamHandler',
'formatter': 'simple',
"stream": "ext://sys.stdout",
"filters": ["warnfilter"]
},
'omlogfile': {
'class': 'logging.handlers.TimedRotatingFileHandler',
'filename': os.path.join(LOG_DIR, 'omflow.log'),
'encoding':'utf-8',
'formatter': 'simple',
'when': 'midnight',
'backupCount': 10,
'delay': True
},
'djangolog': {
'class': 'logging.handlers.TimedRotatingFileHandler',
'filename': os.path.join(LOG_DIR, 'djangolog.log'),
'encoding':'utf-8',
'formatter': 'simple',
'when': 'midnight',
'backupCount': 10,
'delay': True
},
},
'loggers': {
'django': {
'handlers': ['consoleInfo','consoleError','djangolog'],
'level': LOG_LEVEL,
'propagate': False
},
'omflowlog': {
'handlers': ['omlogfile'],
'level': LOG_LEVEL,
'propagate': False
},
},
}
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3","NAME": os.path.join(BASE_DIR, "db.omflow"),"OPTIONS": {"timeout": 300,}}}
这是我的模板:
<!DOCTYPE html>
{% load static %}
{% load i18n %}
{% load omflow_tags %}
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
{% include 'base_import.html' %}
<!-- AdminLTE Skins. We have chosen the skin-blue for this starter
page. However, you can choose any other skin. Make sure you
apply the skin class to the body tag so the changes take effect. -->
<link rel="stylesheet" href="{% static 'css/skins/skin-syscom.css' %}">
<!-- AdminLTE App -->
<script src="{% static 'js/adminlte.min.js' %}"></script>
</head>
<!--
BODY TAG OPTIONS:
=================
Apply one or more of the following classes to get the
desired effect
|---------------------------------------------------------|
| SKINS | skin-blue |
| | skin-black |
| | skin-purple |
| | skin-yellow |
| | skin-red |
| | skin-green |
|---------------------------------------------------------|
|LAYOUT OPTIONS | fixed |
| | layout-boxed |
| | layout-top-nav |
| | sidebar-collapse |
| | sidebar-mini |
|---------------------------------------------------------|
-->
<body class="hold-transition skin-syscom sidebar-mini">
<div class="wrapper">
<!-- Main Header -->
<header class="main-header">
{% include 'base_header.html' %}
</header>
<!-- Left side column. contains the logo and sidebar -->
<aside class="main-sidebar">
{% include 'base_l_aside.html' %}
</aside>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
{% block content %}
{% endblock %}
</div>
<!-- /.content-wrapper -->
<!-- Main Footer -->
<footer class="main-footer">
<!-- To the right -->
<div class="pull-right hidden-xs">
{% omflow_version %} {% omflow_version_type %}
</div>
<!-- Default to the left -->
<strong>© 2020 <a href="#">The SYSCOM Group</a>.</strong> {% trans '版權所有.'%}
</footer>
<!-- Add the sidebar's background. This div must be placed
immediately after the control sidebar -->
<div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->
{% include 'base_component.html' %}
</body>
</html>
这是假设的
{% load static %}
{% load i18n %}
{% load omflow_tags %}
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>OMFLOW</title>
<!-- Tell the browser to be responsive to screen width -->
<link rel="shortcut icon" href="{% static "img/favicon.ico" %}" />
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel="stylesheet" href="{% static 'components/bootstrap/dist/css/bootstrap.min.css' %}">
<link rel="stylesheet" href="{% static 'plugins/fontawesome-free-5.13.0-web/css/all.css' %}">
<link rel="stylesheet" href="{% static 'plugins/fontawesome-free-5.13.0-web/css/v4-shims.css' %}">
<link rel="stylesheet" href="{% static 'components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css'%}">
<link rel="stylesheet" href="{% static 'plugins/timepicker/bootstrap-timepicker.min.css'%}">
<link rel="stylesheet" href="{% static 'components/bootstrap-datetimepicker-master/css/bootstrap-datetimepicker.min.css'%}">
<!-- DataTables -->
<link rel="stylesheet" href="{% static 'components/datatables.net-bs/css/dataTables.bootstrap.min.css'%} ">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" href="{% static 'plugins/iCheck/minimal/blue.css' %}">
<!-- Google Font
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic"> -->
<link rel="stylesheet" href="{% static 'css/jquery-simple-tree-table.css' %}">
<!-- Select2 -->
<link rel="stylesheet" href="{% static 'components/select2/dist/css/select2.css' %}">
<!-- Ion Slider -->
<link rel="stylesheet" href="{% static 'plugins/Ion-Slider/ion.rangeSlider.min.css' %}">
<!-- daterange picker -->
<link rel="stylesheet" href="{% static 'components/bootstrap-daterangepicker/daterangepicker.css' %}">
<link rel="stylesheet" href="{% static 'plugins/CodeMirror/lib/codemirror.css' %}">
<link rel="stylesheet" href="{% static 'plugins/CodeMirror/theme/eclipse.css' %}">
<link rel="stylesheet" href="{% static 'plugins/SweetAlert2/dist/sweetalert2.css'%}">
<link rel="stylesheet" href="{% static 'plugins/select2-to-tree-master/src/select2totree.css' %}">
<link rel="stylesheet" href="{% static 'css/AdminLTE.min.css' %}">
<link rel="stylesheet" href="{% static 'css/omflow.css'%}?version={%omflow_version%}">
<script type="text/javascript" src="{% url 'javascript-catalog' %}"></script>
<!-- jQuery 3 -->
<script src="{% static 'components/jquery/dist/jquery.min.js'%}"></script>
<!-- jQuery UI -->
datetimepicker.min.js'%}"></script>
<script src="{% static 'components/bootstrap-datetimepicker-master/js/locales/bootstrap-datetimepicker.zh-hant.js'%}"></script>
<script src="{% static 'components/bootstrap-datetimepicker-master/js/locales/bootstrap-datetimepicker.zh-hans.js'%}"></script>
<script src="{% static 'components/bootstrap-datetimepicker-master/js/locales/bootstrap-datetimepicker.ja.js'%}"></script>
<!-- DataTables -->
<script src="{% static 'components/datatables.net/js/jquery.dataTables.min.js' %}"></script>
<script src="{% static 'components/datatables.net-bs/js/dataTables.bootstrap.min.js' %}"></script>
<script src="{% static 'js/jquery-simple-tree-table.js' %}"></script>
<!-- Select2 -->
解决方案
你可以在这里找到答案
所以添加到您的 url 以下
from django.conf.urls.static import static
from .settings import STATIC_URL,STATIC_ROOT
urlpatterns += static(STATIC_URL, document_root=STATIC_ROOT)
推荐阅读
- excel - 如何将值复制到最后一行
- excel - 有 Elseif 限制吗?
- symfony - 如何在 Symfony 日志中设置不同的错误级别
- powershell - 如何在 cmd 中设置一个变量,它是来自 powershell 命令结果的字符串?
- php - 解析?在 htaccess 中
- python - 在 python 中的数据帧上使用 group by 后,如何过滤数据帧以返回特定类型的记录?
- capl - 有没有办法让我在独木舟中调整参数?
- excel - 我可以使用这种方法将txt文件导入excel吗?
- cmake - 为什么 Cmake 不构建我的 vulkan/spirv 着色器?
- azure - 有没有办法在 IE11 中更改网络聊天字体大小