秘密密钥在那里,虽然它在django中没有提到秘密密钥 [英] Secret key is there though it is saying no secret key in django
问题描述
追溯(最近的最后一次呼叫):
文件manage.py,行10,在< module>
execute_from_command_line(sys.argv)
文件/home/sroy8091/college/local/lib/python2.7/site-packages/django/core/management/__init__.py,第338行, execute_from_command_line
utility.execute()
文件/home/sroy8091/college/local/lib/python2.7/site-packages/django/core/management/__init__.py,第330行,执行
self.fetch_command(子命令).run_from_argv(self.argv)
文件/home/sroy8091/college/local/lib/python2.7/site-packages/django/core/management/__init__ .py,第190行,fetch_command
klass = load_command_class(app_name,子命令)
文件/home/sroy8091/college/local/lib/python2.7/site-packages/django/core/管理/ __ init__.py,第40行,在load_command_class
module = import_module('%s.management.commands。%s'%(app_name,name))
文件/ usr / lib / python2 .7 / importlib / __ init__.py,第37行,import_module
__import __(name)
文件/home/sroy8091/college/local/lib/python2.7/site-packag es / django / core / management / commands / runserver.py,第14行在< module>
from django.db.migrations.executor import MigrationExecutor
文件/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/migrations/executor.py,第6行,<模块>
来自.loader import MigrationLoader
文件/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/migrations/loader.py,第10行,在< ;模块>
from django.db.migrations.recorder import MigrationRecorder
文件/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/migrations/recorder.py,第9行在< module>
class MigrationRecorder(object):
文件/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/migrations/recorder.py,第23行, MigrationRecorder
class Migration(models.Model):
文件/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/migrations/recorder.py,行24,in Migration
app = models.CharField(max_length = 255)
文件/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/models/fields /__init__.py,第1081行,__init__
super(CharField,self).__ init __(* args,** kwargs)
文件/ home / sroy8091 / college / local / lib / python2。 7 / site-packages / django / db / models / fields / __ init__.py,第161行,__init__
self.db_tablespace = db_tablespace或settings.DEFAULT_INDEX_TABLESPACE
文件/ home / sroy8091 /本地/ lib / python2.7 / site-packages / django / conf / __ init__.py,第48行__getattr__
self._setup(name)
文件/ home / sroy8091 / college / local /lib/python2.7/site- package / django / conf / __ init__.py,第44行,_setup
self._wrapped =设置(settings_module)
文件/home/sroy8091/college/local/lib/python2.7/site -packages / django / conf / __ init__.py,第113行,__init__
raise不正确的配置(SECRET_KEY设置不能为空。)
django.core.exceptions.ImproperlyConfigured:SECRET_KEY设置不能是空的
这是我的开发设置
kgecweb项目的Django设置
使用Django 1.8生成'django-admin startproject'
有关此文件的更多信息,请参阅
https://docs.djangoproject.com/en/1.8/topics/settings/
有关设置及其值的完整列表,请参阅
https://docs.djangoproject.com/en/1.8/ref/settings/
#在项目中构建路径,如下所示:os.path.join( BASE_DIR,...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__ file__)))
#快速启动开发设置 - 不适合生产
#请参阅https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
#安全警告:保留生产秘密密钥!
SECRET_KEY ='my_secret key here'
#安全警告:在生产中不要运行调试打开!
DEBUG = True
#DEBUG = False
ALLOWED_HOSTS = []
#应用程序定义
INSTALLED_APPS =(
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions' ,
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
'administration',
'stdimage',
'dept',
'trplc',#培训和安置应用程序
'教师',
'学生',
'hostels',
'nkn ',
'clibrary',
'page',
'contact'
)
MIDDLEWARE_CLASSES =(
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware' ,
'django.contrib.auth.middleware.Aut henticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF ='kgecweb.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 ='kgecweb.wsgi.application'
#数据库
#https://docs.djangoproject.com /en/1.8/ref/settings/#databases
DATABASES = {
'default':{
'ENGINE':'django.db.backends.mysql',
#'ENGINE':'django.db.backends.sqlite3',
'NAME':os.path.join(BASE_DIR,'db.mysql'),
'USER':' root',
'PASSWORD':'713331',
'HOST':'192.168.33.19',
'PORT':'3306',
#'NAME' os.path.join(BASE_DIR,'db.sqlite3'),
}
}
#国际化
#https://docs.djangoproject.com/ en / 1.8 / topics / i18n /
LANGUAGE_CODE ='en-us'
TIME_ZONE ='亚洲/加尔各答'
USE_I18N = True
USE_L10N = True
USE_TZ = True
#静态文件(CSS,JavaScript,图像)
#https: //docs.djangoproject.com/ en / 1.8 / howto / static-files /
STATICFILES_DIRS =(os.path.join(BASE_DIR,../static),)
#STATIC_ROOT = os .path.join(BASE_DIR,'static')
STATIC_URL ='/ static /'
MEDIA_ROOT = os.path.join(BASE_DIR,'../media')
MEDIA_URL ='/ media /'
我也做了sql命令初始化数据库和密钥这里也不是空的。虽然继续说我不知道如何解决这个问题。
这是我的项目目录
我甚至尝试制作一个settings.py文件
然后尝试:
python manage.py runserver --settings = kgecweb.settings.development
我猜你没有使用内置的setting.py或者你重命名它,或者创建一个目录来处理不同的settings.py。
EDIT
-
确保您的项目在您的python路径,使用它来了解。
import sys
print(sys.path)
-
,或者您可以在kgecweb(应用程序)中创建一个settings.py,然后运行
python manage.py runserver
-
如果它有效,您只需尝试:
python manage.py runserver --settings = kgecweb.settings.development
/ pre>
When i'm running python manage.py runserver or python manage.py migrate. I'm getting these errors
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 190, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 40, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 14, in <module>
from django.db.migrations.executor import MigrationExecutor
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 6, in <module>
from .loader import MigrationLoader
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 10, in <module>
from django.db.migrations.recorder import MigrationRecorder
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 9, in <module>
class MigrationRecorder(object):
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 23, in MigrationRecorder
class Migration(models.Model):
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 24, in Migration
app = models.CharField(max_length=255)
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1081, in __init__
super(CharField, self).__init__(*args, **kwargs)
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 161, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/home/sroy8091/college/local/lib/python2.7/site-packages/django/conf/__init__.py", line 113, in __init__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
This is my development settings
"""
Django settings for kgecweb project.
Generated by 'django-admin startproject' using Django 1.8.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
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.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'my_secret key here'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
#DEBUG = False
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
'administration',
'stdimage',
'dept',
'trplc', # Training and Placement app
'faculty',
'student',
'hostels',
'nkn',
'clibrary',
'page',
'contact'
)
MIDDLEWARE_CLASSES = (
'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',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'kgecweb.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 = 'kgecweb.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
#'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.mysql'),
'USER': 'root',
'PASSWORD': '713331',
'HOST': '192.168.33.19',
'PORT': '3306',
#'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Kolkata'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATICFILES_DIRS = (os.path.join(BASE_DIR, "../static"),)
#STATIC_ROOT= os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
MEDIA_ROOT = os.path.join(BASE_DIR, '../media')
MEDIA_URL = '/media/'
I also have made the sql command for initializing database and secret key is also not empty here. Though it keep on saying. i don't know how to tackle this. This is my project directory
I even tried making a settings.py file then also this error is coming.
Then try:
python manage.py runserver --settings=kgecweb.settings.development
I guess your didn't use the build-in setting.py or you rename it or make a directory to handle different settings.py.
EDIT
Make sure your project in your python path, use this to find out.
import sys print(sys.path)
or you can just create a settings.py in kgecweb(the app) then run
python manage.py runserver
if it works, you just try:
python manage.py runserver --settings=kgecweb.settings.development
这篇关于秘密密钥在那里,虽然它在django中没有提到秘密密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!