我仔細閱讀了documentation以及與該主題相關的多個討論,但仍無法確定降價停止的位置。我只想在Django視圖中打開一個靜態文件,向其中寫入一些內容並將其保存使用Django - 從服務器打開靜態文件
f = open('/static/egais_files/temp.txt', 'w')
方法。
我的設置:
"""
Django settings for supermarket_project project.
Generated by 'django-admin startproject' using Django 1.9.1.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""
#for gmail or goole apps
from supermarket_project.email_info import EMAIL_USE_TLS,EMAIL_HOST,EMAIL_HOST_USER,EMAIL_HOST_PASSWORD,EMAIL_PORT
from django.conf.global_settings import ALLOWED_HOSTS
#What Tigran wrote ---------------------------------------------------------------------------------
EMAIL_USE_TLS = EMAIL_USE_TLS
EMAIL_HOST = EMAIL_HOST
EMAIL_HOST_USER = EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = EMAIL_HOST_PASSWORD
EMAIL_PORT = EMAIL_PORT
#What Tigran wrote END ------------------------------------------------------------------------------
import os
#from django.conf.global_settings import TEMPLATE_DEBUG
# 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/1.9/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'pvpsr%xjy3ki8ecut2&x=!+&(1q*=u9=(tnz8o371m^%^jntn&'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
#ALLOWED_HOSTS= ['*']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'person',
'legal_entity',
'additional',
'address',
'employee',
'agreement',
'report',
'vendor',
'bootstrap3_datetime',
'computer_repair',
'task',
'egais',
]
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'supermarket_project.urls'
#ANONYMOUS_USER_ID=-1
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.dirname(BASE_DIR),"static","templates")],
#'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 = 'supermarket_project.wsgi.application'
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
#===============================================================================
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# }
# }
#===============================================================================
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'supermarkets_schema',
'USER': 'edgar',
'PASSWORD': '123',
'HOST': '10.8.0.1', # Or an IP Address that your DB is hosted on
'PORT': '3306',
'default-character-set': 'utf8',
},
'computer_repair': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'computer_repair',
'USER': 'edgar',
'PASSWORD': '123',
'HOST': '10.8.0.1', # Or an IP Address that your DB is hosted on
'PORT': '3306',
'default-character-set': 'utf8',
}
}
#DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.mysql',
# 'NAME': 'test',
# 'USER': 'root',
# 'PASSWORD': '1234',
# }
#}
# Password validation
# https://docs.djangoproject.com/en/1.9/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/1.9/topics/i18n/
LANGUAGE_CODE = 'ru'
TIME_ZONE = 'Europe/Moscow'
USE_I18N = True
USE_L10N = True
USE_TZ = False
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_URL = '/static/'
if DEBUG:
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR),"static","static")
#STATIC_ROOT = [os.path.join(BASE_DIR,"static-only")]
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR),"static","media")
#MEDIA_ROOT = [os.path.join(BASE_DIR,"media")]
STATICFILES_DIRS = (
os.path.join(os.path.dirname(BASE_DIR),"static","static"),
)
看起來一切都對應於什麼文件說。請幫幫我 !錯誤在哪裏?
謝謝。它不能識別os.join,儘管事實上我輸入了os –
對不起,應該是'os.path.join'(就像在你的settings.py中) – ilse2005
不行,沒有工作[錯誤2]沒有這樣的文件或目錄: '\\\\ 10.8.0.1 \\ share/egais_files/temp.txt \\ w' –