Ich habe sorgfältig documentation und mehrere Diskussionen im Zusammenhang mit dem Thema gelesen, kann aber immer noch nicht herausfinden, wo der Dollar aufhört. Ich möchte nur eine statische Datei in Django-Ansicht öffnen, einige Inhalte in sie schreiben und esDjango - statische Datei vom Server öffnen
f = open('/static/egais_files/temp.txt', 'w')
Methode zu speichern.
Meine Einstellungen:
"""
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"),
)
wie alles Sieht aus dem entspricht, was Dokumentation sagt. Hilf mir bitte ! Wo ist der Fehler ???
Danke. Es kann os.join nicht erkennen, trotz der Tatsache, dass ich os importiert –
Sorry, sollte 'os.path.join' (wie in Ihrer settings.py) – ilse2005
Nein, hat nicht funktioniert [Errno 2] Keine solche Datei oder Verzeichnis: '\\\\ 10.8.0.1 \\ share/egais_files/temp.txt \\ w' –