Django配置文件

 

配置文件源码

django.conf.global_settings.py 下面的全局初始配置文件:

  1 # -*- coding: utf-8 -*-
  2 """
  3 Default Django settings. Override these with settings in the module pointed to
  4 by the DJANGO_SETTINGS_MODULE environment variable.
  5 """
  6 from __future__ import unicode_literals
  7 
  8 
  9 # This is defined here as a do-nothing function because we can't import
 10 # django.utils.translation -- that module depends on the settings.
 11 def gettext_noop(s):
 12     return s
 13 
 14 
 15 ####################
 16 # CORE             #
 17 ####################
 18 
 19 DEBUG = False
 20 
 21 # Whether the framework should propagate raw exceptions rather than catching
 22 # them. This is useful under some testing situations and should never be used
 23 # on a live site.
 24 DEBUG_PROPAGATE_EXCEPTIONS = False
 25 
 26 # Whether to use the "ETag" header. This saves bandwidth but slows down performance.
 27 # Deprecated (RemovedInDjango21Warning) in favor of ConditionalGetMiddleware
 28 # which sets the ETag regardless of this setting.
 29 USE_ETAGS = False
 30 
 31 # People who get code error notifications.
 32 # In the format [('Full Name', 'email@example.com'), ('Full Name', 'anotheremail@example.com')]
 33 ADMINS = []
 34 
 35 # List of IP addresses, as strings, that:
 36 #   * See debug comments, when DEBUG is true
 37 #   * Receive x-headers
 38 INTERNAL_IPS = []
 39 
 40 # Hosts/domain names that are valid for this site.
 41 # "*" matches anything, ".example.com" matches example.com and all subdomains
 42 ALLOWED_HOSTS = []
 43 
 44 # Local time zone for this installation. All choices can be found here:
 45 # https://en.wikipedia.org/wiki/List_of_tz_zones_by_name (although not all
 46 # systems may support all possibilities). When USE_TZ is True, this is
 47 # interpreted as the default user time zone.
 48 TIME_ZONE = 'America/Chicago'
 49 
 50 # If you set this to True, Django will use timezone-aware datetimes.
 51 USE_TZ = False
 52 
 53 # Language code for this installation. All choices can be found here:
 54 # http://www.i18nguy.com/unicode/language-identifiers.html
 55 LANGUAGE_CODE = 'en-us'
 56 
 57 # Languages we provide translations for, out of the box.
 58 LANGUAGES = [
 59     ('af', gettext_noop('Afrikaans')),
 60     ('ar', gettext_noop('Arabic')),
 61     ('ast', gettext_noop('Asturian')),
 62     ('az', gettext_noop('Azerbaijani')),
 63     ('bg', gettext_noop('Bulgarian')),
 64     ('be', gettext_noop('Belarusian')),
 65     ('bn', gettext_noop('Bengali')),
 66     ('br', gettext_noop('Breton')),
 67     ('bs', gettext_noop('Bosnian')),
 68     ('ca', gettext_noop('Catalan')),
 69     ('cs', gettext_noop('Czech')),
 70     ('cy', gettext_noop('Welsh')),
 71     ('da', gettext_noop('Danish')),
 72     ('de', gettext_noop('German')),
 73     ('dsb', gettext_noop('Lower Sorbian')),
 74     ('el', gettext_noop('Greek')),
 75     ('en', gettext_noop('English')),
 76     ('en-au', gettext_noop('Australian English')),
 77     ('en-gb', gettext_noop('British English')),
 78     ('eo', gettext_noop('Esperanto')),
 79     ('es', gettext_noop('Spanish')),
 80     ('es-ar', gettext_noop('Argentinian Spanish')),
 81     ('es-co', gettext_noop('Colombian Spanish')),
 82     ('es-mx', gettext_noop('Mexican Spanish')),
 83     ('es-ni', gettext_noop('Nicaraguan Spanish')),
 84     ('es-ve', gettext_noop('Venezuelan Spanish')),
 85     ('et', gettext_noop('Estonian')),
 86     ('eu', gettext_noop('Basque')),
 87     ('fa', gettext_noop('Persian')),
 88     ('fi', gettext_noop('Finnish')),
 89     ('fr', gettext_noop('French')),
 90     ('fy', gettext_noop('Frisian')),
 91     ('ga', gettext_noop('Irish')),
 92     ('gd', gettext_noop('Scottish Gaelic')),
 93     ('gl', gettext_noop('Galician')),
 94     ('he', gettext_noop('Hebrew')),
 95     ('hi', gettext_noop('Hindi')),
 96     ('hr', gettext_noop('Croatian')),
 97     ('hsb', gettext_noop('Upper Sorbian')),
 98     ('hu', gettext_noop('Hungarian')),
 99     ('ia', gettext_noop('Interlingua')),
100     ('id', gettext_noop('Indonesian')),
101     ('io', gettext_noop('Ido')),
102     ('is', gettext_noop('Icelandic')),
103     ('it', gettext_noop('Italian')),
104     ('ja', gettext_noop('Japanese')),
105     ('ka', gettext_noop('Georgian')),
106     ('kk', gettext_noop('Kazakh')),
107     ('km', gettext_noop('Khmer')),
108     ('kn', gettext_noop('Kannada')),
109     ('ko', gettext_noop('Korean')),
110     ('lb', gettext_noop('Luxembourgish')),
111     ('lt', gettext_noop('Lithuanian')),
112     ('lv', gettext_noop('Latvian')),
113     ('mk', gettext_noop('Macedonian')),
114     ('ml', gettext_noop('Malayalam')),
115     ('mn', gettext_noop('Mongolian')),
116     ('mr', gettext_noop('Marathi')),
117     ('my', gettext_noop('Burmese')),
118     ('nb', gettext_noop('Norwegian Bokmål')),
119     ('ne', gettext_noop('Nepali')),
120     ('nl', gettext_noop('Dutch')),
121     ('nn', gettext_noop('Norwegian Nynorsk')),
122     ('os', gettext_noop('Ossetic')),
123     ('pa', gettext_noop('Punjabi')),
124     ('pl', gettext_noop('Polish')),
125     ('pt', gettext_noop('Portuguese')),
126     ('pt-br', gettext_noop('Brazilian Portuguese')),
127     ('ro', gettext_noop('Romanian')),
128     ('ru', gettext_noop('Russian')),
129     ('sk', gettext_noop('Slovak')),
130     ('sl', gettext_noop('Slovenian')),
131     ('sq', gettext_noop('Albanian')),
132     ('sr', gettext_noop('Serbian')),
133     ('sr-latn', gettext_noop('Serbian Latin')),
134     ('sv', gettext_noop('Swedish')),
135     ('sw', gettext_noop('Swahili')),
136     ('ta', gettext_noop('Tamil')),
137     ('te', gettext_noop('Telugu')),
138     ('th', gettext_noop('Thai')),
139     ('tr', gettext_noop('Turkish')),
140     ('tt', gettext_noop('Tatar')),
141     ('udm', gettext_noop('Udmurt')),
142     ('uk', gettext_noop('Ukrainian')),
143     ('ur', gettext_noop('Urdu')),
144     ('vi', gettext_noop('Vietnamese')),
145     ('zh-hans', gettext_noop('Simplified Chinese')),
146     ('zh-hant', gettext_noop('Traditional Chinese')),
147 ]
148 
149 # Languages using BiDi (right-to-left) layout
150 LANGUAGES_BIDI = ["he", "ar", "fa", "ur"]
151 
152 # If you set this to False, Django will make some optimizations so as not
153 # to load the internationalization machinery.
154 USE_I18N = True
155 LOCALE_PATHS = []
156 
157 # Settings for language cookie
158 LANGUAGE_COOKIE_NAME = 'django_language'
159 LANGUAGE_COOKIE_AGE = None
160 LANGUAGE_COOKIE_DOMAIN = None
161 LANGUAGE_COOKIE_PATH = '/'
162 
163 
164 # If you set this to True, Django will format dates, numbers and calendars
165 # according to user current locale.
166 USE_L10N = False
167 
168 # Not-necessarily-technical managers of the site. They get broken link
169 # notifications and other various emails.
170 MANAGERS = ADMINS
171 
172 # Default content type and charset to use for all HttpResponse objects, if a
173 # MIME type isn't manually specified. These are used to construct the
174 # Content-Type header.
175 DEFAULT_CONTENT_TYPE = 'text/html'
176 DEFAULT_CHARSET = 'utf-8'
177 
178 # Encoding of files read from disk (template and initial SQL files).
179 FILE_CHARSET = 'utf-8'
180 
181 # Email address that error messages come from.
182 SERVER_EMAIL = 'root@localhost'
183 
184 # Database connection info. If left empty, will default to the dummy backend.
185 DATABASES = {}
186 
187 # Classes used to implement DB routing behavior.
188 DATABASE_ROUTERS = []
189 
190 # The email backend to use. For possible shortcuts see django.core.mail.
191 # The default is to use the SMTP backend.
192 # Third-party backends can be specified by providing a Python path
193 # to a module that defines an EmailBackend class.
194 EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
195 
196 # Host for sending email.
197 EMAIL_HOST = 'localhost'
198 
199 # Port for sending email.
200 EMAIL_PORT = 25
201 
202 # Whether to send SMTP 'Date' header in the local time zone or in UTC.
203 EMAIL_USE_LOCALTIME = False
204 
205 # Optional SMTP authentication information for EMAIL_HOST.
206 EMAIL_HOST_USER = ''
207 EMAIL_HOST_PASSWORD = ''
208 EMAIL_USE_TLS = False
209 EMAIL_USE_SSL = False
210 EMAIL_SSL_CERTFILE = None
211 EMAIL_SSL_KEYFILE = None
212 EMAIL_TIMEOUT = None
213 
214 # List of strings representing installed apps.
215 INSTALLED_APPS = []
216 
217 TEMPLATES = []
218 
219 # Default form rendering class.
220 FORM_RENDERER = 'django.forms.renderers.DjangoTemplates'
221 
222 # Default email address to use for various automated correspondence from
223 # the site managers.
224 DEFAULT_FROM_EMAIL = 'webmaster@localhost'
225 
226 # Subject-line prefix for email messages send with django.core.mail.mail_admins
227 # or ...mail_managers.  Make sure to include the trailing space.
228 EMAIL_SUBJECT_PREFIX = '[Django] '
229 
230 # Whether to append trailing slashes to URLs.
231 APPEND_SLASH = True
232 
233 # Whether to prepend the "www." subdomain to URLs that don't have it.
234 PREPEND_WWW = False
235 
236 # Override the server-derived value of SCRIPT_NAME
237 FORCE_SCRIPT_NAME = None
238 
239 # List of compiled regular expression objects representing User-Agent strings
240 # that are not allowed to visit any page, systemwide. Use this for bad
241 # robots/crawlers. Here are a few examples:
242 #     import re
243 #     DISALLOWED_USER_AGENTS = [
244 #         re.compile(r'^NaverBot.*'),
245 #         re.compile(r'^EmailSiphon.*'),
246 #         re.compile(r'^SiteSucker.*'),
247 #         re.compile(r'^sohu-search'),
248 #     ]
249 DISALLOWED_USER_AGENTS = []
250 
251 ABSOLUTE_URL_OVERRIDES = {}
252 
253 # List of compiled regular expression objects representing URLs that need not
254 # be reported by BrokenLinkEmailsMiddleware. Here are a few examples:
255 #    import re
256 #    IGNORABLE_404_URLS = [
257 #        re.compile(r'^/apple-touch-icon.*\.png$'),
258 #        re.compile(r'^/favicon.ico$'),
259 #        re.compile(r'^/robots.txt$'),
260 #        re.compile(r'^/phpmyadmin/'),
261 #        re.compile(r'\.(cgi|php|pl)$'),
262 #    ]
263 IGNORABLE_404_URLS = []
264 
265 # A secret key for this particular Django installation. Used in secret-key
266 # hashing algorithms. Set this in your settings, or Django will complain
267 # loudly.
268 SECRET_KEY = ''
269 
270 # Default file storage mechanism that holds media.
271 DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'
272 
273 # Absolute filesystem path to the directory that will hold user-uploaded files.
274 # Example: "/var/www/example.com/media/"
275 MEDIA_ROOT = ''
276 
277 # URL that handles the media served from MEDIA_ROOT.
278 # Examples: "http://example.com/media/", "http://media.example.com/"
279 MEDIA_URL = ''
280 
281 # Absolute path to the directory static files should be collected to.
282 # Example: "/var/www/example.com/static/"
283 STATIC_ROOT = None
284 
285 # URL that handles the static files served from STATIC_ROOT.
286 # Example: "http://example.com/static/", "http://static.example.com/"
287 STATIC_URL = None
288 
289 # List of upload handler classes to be applied in order.
290 FILE_UPLOAD_HANDLERS = [
291     'django.core.files.uploadhandler.MemoryFileUploadHandler',
292     'django.core.files.uploadhandler.TemporaryFileUploadHandler',
293 ]
294 
295 # Maximum size, in bytes, of a request before it will be streamed to the
296 # file system instead of into memory.
297 FILE_UPLOAD_MAX_MEMORY_SIZE = 2621440  # i.e. 2.5 MB
298 
299 # Maximum size in bytes of request data (excluding file uploads) that will be
300 # read before a SuspiciousOperation (RequestDataTooBig) is raised.
301 DATA_UPLOAD_MAX_MEMORY_SIZE = 2621440  # i.e. 2.5 MB
302 
303 # Maximum number of GET/POST parameters that will be read before a
304 # SuspiciousOperation (TooManyFieldsSent) is raised.
305 DATA_UPLOAD_MAX_NUMBER_FIELDS = 1000
306 
307 # Directory in which upload streamed files will be temporarily saved. A value of
308 # `None` will make Django use the operating system's default temporary directory
309 # (i.e. "/tmp" on *nix systems).
310 FILE_UPLOAD_TEMP_DIR = None
311 
312 # The numeric mode to set newly-uploaded files to. The value should be a mode
313 # you'd pass directly to os.chmod; see https://docs.python.org/3/library/os.html#files-and-directories.
314 FILE_UPLOAD_PERMISSIONS = None
315 
316 # The numeric mode to assign to newly-created directories, when uploading files.
317 # The value should be a mode as you'd pass to os.chmod;
318 # see https://docs.python.org/3/library/os.html#files-and-directories.
319 FILE_UPLOAD_DIRECTORY_PERMISSIONS = None
320 
321 # Python module path where user will place custom format definition.
322 # The directory where this setting is pointing should contain subdirectories
323 # named as the locales, containing a formats.py file
324 # (i.e. "myproject.locale" for myproject/locale/en/formats.py etc. use)
325 FORMAT_MODULE_PATH = None
326 
327 # Default formatting for date objects. See all available format strings here:
328 # http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
329 DATE_FORMAT = 'N j, Y'
330 
331 # Default formatting for datetime objects. See all available format strings here:
332 # http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
333 DATETIME_FORMAT = 'N j, Y, P'
334 
335 # Default formatting for time objects. See all available format strings here:
336 # http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
337 TIME_FORMAT = 'P'
338 
339 # Default formatting for date objects when only the year and month are relevant.
340 # See all available format strings here:
341 # http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
342 YEAR_MONTH_FORMAT = 'F Y'
343 
344 # Default formatting for date objects when only the month and day are relevant.
345 # See all available format strings here:
346 # http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
347 MONTH_DAY_FORMAT = 'F j'
348 
349 # Default short formatting for date objects. See all available format strings here:
350 # http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
351 SHORT_DATE_FORMAT = 'm/d/Y'
352 
353 # Default short formatting for datetime objects.
354 # See all available format strings here:
355 # http://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
356 SHORT_DATETIME_FORMAT = 'm/d/Y P'
357 
358 # Default formats to be used when parsing dates from input boxes, in order
359 # See all available format string here:
360 # http://docs.python.org/library/datetime.html#strftime-behavior
361 # * Note that these format strings are different from the ones to display dates
362 DATE_INPUT_FORMATS = [
363     '%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y',  # '2006-10-25', '10/25/2006', '10/25/06'
364     '%b %d %Y', '%b %d, %Y',             # 'Oct 25 2006', 'Oct 25, 2006'
365     '%d %b %Y', '%d %b, %Y',             # '25 Oct 2006', '25 Oct, 2006'
366     '%B %d %Y', '%B %d, %Y',             # 'October 25 2006', 'October 25, 2006'
367     '%d %B %Y', '%d %B, %Y',             # '25 October 2006', '25 October, 2006'
368 ]
369 
370 # Default formats to be used when parsing times from input boxes, in order
371 # See all available format string here:
372 # http://docs.python.org/library/datetime.html#strftime-behavior
373 # * Note that these format strings are different from the ones to display dates
374 TIME_INPUT_FORMATS = [
375     '%H:%M:%S',     # '14:30:59'
376     '%H:%M:%S.%f',  # '14:30:59.000200'
377     '%H:%M',        # '14:30'
378 ]
379 
380 # Default formats to be used when parsing dates and times from input boxes,
381 # in order
382 # See all available format string here:
383 # http://docs.python.org/library/datetime.html#strftime-behavior
384 # * Note that these format strings are different from the ones to display dates
385 DATETIME_INPUT_FORMATS = [
386     '%Y-%m-%d %H:%M:%S',     # '2006-10-25 14:30:59'
387     '%Y-%m-%d %H:%M:%S.%f',  # '2006-10-25 14:30:59.000200'
388     '%Y-%m-%d %H:%M',        # '2006-10-25 14:30'
389     '%Y-%m-%d',              # '2006-10-25'
390     '%m/%d/%Y %H:%M:%S',     # '10/25/2006 14:30:59'
391     '%m/%d/%Y %H:%M:%S.%f',  # '10/25/2006 14:30:59.000200'
392     '%m/%d/%Y %H:%M',        # '10/25/2006 14:30'
393     '%m/%d/%Y',              # '10/25/2006'
394     '%m/%d/%y %H:%M:%S',     # '10/25/06 14:30:59'
395     '%m/%d/%y %H:%M:%S.%f',  # '10/25/06 14:30:59.000200'
396     '%m/%d/%y %H:%M',        # '10/25/06 14:30'
397     '%m/%d/%y',              # '10/25/06'
398 ]
399 
400 # First day of week, to be used on calendars
401 # 0 means Sunday, 1 means Monday...
402 FIRST_DAY_OF_WEEK = 0
403 
404 # Decimal separator symbol
405 DECIMAL_SEPARATOR = '.'
406 
407 # Boolean that sets whether to add thousand separator when formatting numbers
408 USE_THOUSAND_SEPARATOR = False
409 
410 # Number of digits that will be together, when splitting them by
411 # THOUSAND_SEPARATOR. 0 means no grouping, 3 means splitting by thousands...
412 NUMBER_GROUPING = 0
413 
414 # Thousand separator symbol
415 THOUSAND_SEPARATOR = ','
416 
417 # The tablespaces to use for each model when not specified otherwise.
418 DEFAULT_TABLESPACE = ''
419 DEFAULT_INDEX_TABLESPACE = ''
420 
421 # Default X-Frame-Options header value
422 X_FRAME_OPTIONS = 'SAMEORIGIN'
423 
424 USE_X_FORWARDED_HOST = False
425 USE_X_FORWARDED_PORT = False
426 
427 # The Python dotted path to the WSGI application that Django's internal server
428 # (runserver) will use. If `None`, the return value of
429 # 'django.core.wsgi.get_wsgi_application' is used, thus preserving the same
430 # behavior as previous versions of Django. Otherwise this should point to an
431 # actual WSGI application object.
432 WSGI_APPLICATION = None
433 
434 # If your Django app is behind a proxy that sets a header to specify secure
435 # connections, AND that proxy ensures that user-submitted headers with the
436 # same name are ignored (so that people can't spoof it), set this value to
437 # a tuple of (header_name, header_value). For any requests that come in with
438 # that header/value, request.is_secure() will return True.
439 # WARNING! Only set this if you fully understand what you're doing. Otherwise,
440 # you may be opening yourself up to a security risk.
441 SECURE_PROXY_SSL_HEADER = None
442 
443 ##############
444 # MIDDLEWARE #
445 ##############
446 
447 # List of middleware to use. Order is important; in the request phase, these
448 # middleware will be applied in the order given, and in the response
449 # phase the middleware will be applied in reverse order.
450 MIDDLEWARE_CLASSES = [
451     'django.middleware.common.CommonMiddleware',
452     'django.middleware.csrf.CsrfViewMiddleware',
453 ]
454 
455 MIDDLEWARE = None
456 
457 ############
458 # SESSIONS #
459 ############
460 
461 # Cache to store session data if using the cache session backend.
462 SESSION_CACHE_ALIAS = 'default'
463 # Cookie name. This can be whatever you want.
464 SESSION_COOKIE_NAME = 'sessionid'
465 # Age of cookie, in seconds (default: 2 weeks).
466 SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 2
467 # A string like ".example.com", or None for standard domain cookie.
468 SESSION_COOKIE_DOMAIN = None
469 # Whether the session cookie should be secure (https:// only).
470 SESSION_COOKIE_SECURE = False
471 # The path of the session cookie.
472 SESSION_COOKIE_PATH = '/'
473 # Whether to use the non-RFC standard httpOnly flag (IE, FF3+, others)
474 SESSION_COOKIE_HTTPONLY = True
475 # Whether to save the session data on every request.
476 SESSION_SAVE_EVERY_REQUEST = False
477 # Whether a user's session cookie expires when the Web browser is closed.
478 SESSION_EXPIRE_AT_BROWSER_CLOSE = False
479 # The module to store session data
480 SESSION_ENGINE = 'django.contrib.sessions.backends.db'
481 # Directory to store session files if using the file session module. If None,
482 # the backend will use a sensible default.
483 SESSION_FILE_PATH = None
484 # class to serialize session data
485 SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'
486 
487 #########
488 # CACHE #
489 #########
490 
491 # The cache backends to use.
492 CACHES = {
493     'default': {
494         'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
495     }
496 }
497 CACHE_MIDDLEWARE_KEY_PREFIX = ''
498 CACHE_MIDDLEWARE_SECONDS = 600
499 CACHE_MIDDLEWARE_ALIAS = 'default'
500 
501 ##################
502 # AUTHENTICATION #
503 ##################
504 
505 AUTH_USER_MODEL = 'auth.User'
506 
507 AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.ModelBackend']
508 
509 LOGIN_URL = '/accounts/login/'
510 
511 LOGIN_REDIRECT_URL = '/accounts/profile/'
512 
513 LOGOUT_REDIRECT_URL = None
514 
515 # The number of days a password reset link is valid for
516 PASSWORD_RESET_TIMEOUT_DAYS = 3
517 
518 # the first hasher in this list is the preferred algorithm.  any
519 # password using different algorithms will be converted automatically
520 # upon login
521 PASSWORD_HASHERS = [
522     'django.contrib.auth.hashers.PBKDF2PasswordHasher',
523     'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
524     'django.contrib.auth.hashers.Argon2PasswordHasher',
525     'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
526     'django.contrib.auth.hashers.BCryptPasswordHasher',
527 ]
528 
529 AUTH_PASSWORD_VALIDATORS = []
530 
531 ###########
532 # SIGNING #
533 ###########
534 
535 SIGNING_BACKEND = 'django.core.signing.TimestampSigner'
536 
537 ########
538 # CSRF #
539 ########
540 
541 # Dotted path to callable to be used as view when a request is
542 # rejected by the CSRF middleware.
543 CSRF_FAILURE_VIEW = 'django.views.csrf.csrf_failure'
544 
545 # Settings for CSRF cookie.
546 CSRF_COOKIE_NAME = 'csrftoken'
547 CSRF_COOKIE_AGE = 60 * 60 * 24 * 7 * 52
548 CSRF_COOKIE_DOMAIN = None
549 CSRF_COOKIE_PATH = '/'
550 CSRF_COOKIE_SECURE = False
551 CSRF_COOKIE_HTTPONLY = False
552 CSRF_HEADER_NAME = 'HTTP_X_CSRFTOKEN'
553 CSRF_TRUSTED_ORIGINS = []
554 CSRF_USE_SESSIONS = False
555 
556 ############
557 # MESSAGES #
558 ############
559 
560 # Class to use as messages backend
561 MESSAGE_STORAGE = 'django.contrib.messages.storage.fallback.FallbackStorage'
562 
563 # Default values of MESSAGE_LEVEL and MESSAGE_TAGS are defined within
564 # django.contrib.messages to avoid imports in this settings file.
565 
566 ###########
567 # LOGGING #
568 ###########
569 
570 # The callable to use to configure logging
571 LOGGING_CONFIG = 'logging.config.dictConfig'
572 
573 # Custom logging configuration.
574 LOGGING = {}
575 
576 # Default exception reporter filter class used in case none has been
577 # specifically assigned to the HttpRequest instance.
578 DEFAULT_EXCEPTION_REPORTER_FILTER = 'django.views.debug.SafeExceptionReporterFilter'
579 
580 ###########
581 # TESTING #
582 ###########
583 
584 # The name of the class to use to run the test suite
585 TEST_RUNNER = 'django.test.runner.DiscoverRunner'
586 
587 # Apps that don't need to be serialized at test database creation time
588 # (only apps with migrations are to start with)
589 TEST_NON_SERIALIZED_APPS = []
590 
591 ############
592 # FIXTURES #
593 ############
594 
595 # The list of directories to search for fixtures
596 FIXTURE_DIRS = []
597 
598 ###############
599 # STATICFILES #
600 ###############
601 
602 # A list of locations of additional static files
603 STATICFILES_DIRS = []
604 
605 # The default file storage backend used during the build process
606 STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
607 
608 # List of finder classes that know how to find static files in
609 # various locations.
610 STATICFILES_FINDERS = [
611     'django.contrib.staticfiles.finders.FileSystemFinder',
612     'django.contrib.staticfiles.finders.AppDirectoriesFinder',
613     # 'django.contrib.staticfiles.finders.DefaultStorageFinder',
614 ]
615 
616 ##############
617 # MIGRATIONS #
618 ##############
619 
620 # Migration module overrides for apps, by app label.
621 MIGRATION_MODULES = {}
622 
623 #################
624 # SYSTEM CHECKS #
625 #################
626 
627 # List of all issues generated by system checks that should be silenced. Light
628 # issues like warnings, infos or debugs will not generate a message. Silencing
629 # serious issues like errors and criticals does not result in hiding the
630 # message, but Django will not stop you from e.g. running server.
631 SILENCED_SYSTEM_CHECKS = []
632 
633 #######################
634 # SECURITY MIDDLEWARE #
635 #######################
636 SECURE_BROWSER_XSS_FILTER = False
637 SECURE_CONTENT_TYPE_NOSNIFF = False
638 SECURE_HSTS_INCLUDE_SUBDOMAINS = False
639 SECURE_HSTS_PRELOAD = False
640 SECURE_HSTS_SECONDS = 0
641 SECURE_REDIRECT_EXEMPT = []
642 SECURE_SSL_HOST = None
643 SECURE_SSL_REDIRECT = False
View Code

创建项目后自定义的配置文件 settings.py

  1 """
  2 Django settings for luffy_permission project.
  3 
  4 Generated by 'django-admin startproject' using Django 1.11.7.
  5 
  6 For more information on this file, see
  7 https://docs.djangoproject.com/en/1.11/topics/settings/
  8 
  9 For the full list of settings and their values, see
 10 https://docs.djangoproject.com/en/1.11/ref/settings/
 11 """
 12 
 13 import os
 14 
 15 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
 16 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 17 
 18 # Quick-start development settings - unsuitable for production
 19 # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
 20 
 21 # SECURITY WARNING: keep the secret key used in production secret!
 22 SECRET_KEY = '-t5hehq#zmk=_m)!6pm(c8_s-ycack)$dpppm7ws!&0#eljwzs'
 23 
 24 # SECURITY WARNING: don't run with debug turned on in production!
 25 DEBUG = True
 26 
 27 ALLOWED_HOSTS = []
 28 
 29 # Application definition
 30 
 31 INSTALLED_APPS = [
 32     'django.contrib.admin',
 33     'django.contrib.auth',
 34     'django.contrib.contenttypes',
 35     'django.contrib.sessions',
 36     'django.contrib.messages',
 37     'django.contrib.staticfiles',
 38     'rbac.apps.RbacConfig',
 39     'web.apps.WebConfig'
 40 ]
 41 # from django.middleware.clickjacking import XFrameOptionsMiddleware
 42 MIDDLEWARE = [
 43     'django.middleware.security.SecurityMiddleware',
 44     'django.contrib.sessions.middleware.SessionMiddleware',
 45     'django.middleware.common.CommonMiddleware',
 46     'django.middleware.csrf.CsrfViewMiddleware',
 47     'django.contrib.auth.middleware.AuthenticationMiddleware',
 48     'django.contrib.messages.middleware.MessageMiddleware',
 49     'django.middleware.clickjacking.XFrameOptionsMiddleware',
 50     # "rbac.middleware.permission_csrf.PermissionMiddleware",
 51 ]
 52 
 53 ROOT_URLCONF = 'luffy_permission.urls'
 54 
 55 TEMPLATES = [
 56     {
 57         'BACKEND': 'django.template.backends.django.DjangoTemplates',
 58         'DIRS': [os.path.join(BASE_DIR, 'templates')]
 59         ,
 60         'APP_DIRS': True,
 61         'OPTIONS': {
 62             'context_processors': [
 63                 'django.template.context_processors.debug',
 64                 'django.template.context_processors.request',
 65                 'django.contrib.auth.context_processors.auth',
 66                 'django.contrib.messages.context_processors.messages',
 67             ],
 68         },
 69     },
 70 ]
 71 
 72 WSGI_APPLICATION = 'luffy_permission.wsgi.application'
 73 
 74 # Database
 75 # https://docs.djangoproject.com/en/1.11/ref/settings/#databases
 76 
 77 DATABASES = {
 78     'default': {
 79         'ENGINE': 'django.db.backends.sqlite3',
 80         'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
 81     }
 82 }
 83 
 84 # Password validation
 85 # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
 86 
 87 AUTH_PASSWORD_VALIDATORS = [
 88     {
 89         'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
 90     },
 91     {
 92         'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
 93     },
 94     {
 95         'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
 96     },
 97     {
 98         'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
 99     },
100 ]
101 
102 # Internationalization
103 # https://docs.djangoproject.com/en/1.11/topics/i18n/
104 
105 LANGUAGE_CODE = 'en-us'
106 
107 TIME_ZONE = 'UTC'
108 
109 USE_I18N = True
110 
111 USE_L10N = True
112 
113 USE_TZ = True
114 
115 # Static files (CSS, JavaScript, Images)
116 # https://docs.djangoproject.com/en/1.11/howto/static-files/
117 
118 STATIC_URL = '/static/'
View Code

 

在项目中的settings.py文件中修改添加里面的内容,也可以对全局的配置文件,起到影响。因为在项目开启后,会加载当前项目中的配置文件。

 

配置文件重点内容解析说明

 - 项目当中的配置文件的解析说明:

  - BASE_DIR : 该变量是指当前项目的绝对路径的,

"""
假如你的项目创建在D盘的根目录,且你项目的名字叫做:mysite_1
那么,现在的BASE_DIR就等于:
"""

"E:\mysite_1"
示例

 

  - ALLOWED_HOSTS:允许访问的域名; 

"""
ALLOWED_HOSTS 的值是一个列表,列表里面存放允许 访问本django项目的 网段
"""

# 如果想让所有人都可以访问,就在列表中放一个"*" :
ALLOWED_HOSTS = ["*"]

 

  INSTALLED_APPS:注册的APP

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rbac.apps.RbacConfig',
    'web.apps.WebConfig'
]

# 当项目新创建了APP后,需要将app在这里进行记录

 

  MIDDLEWARE:中间件的注册, 跟app一样,当自定义了中间件需要在这里添加,不然,不会执行。

 

  TEMPLATES: 模板相关配置;

 

  DATABASES:连接数据库相关配置;

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': orm, # 数据库的名字
        "USERNAME": "root",
        "PASSWORD": "root",
        "PORT": 3306,
        "HOST": "127.0.0.1"  
    }
}
示例,连接mysql数据库

 

  STATIC_URL:静态文件的配置:

STATIC_URL : 这个是静态文件的别名, 默认为"/static/"

# 配置静态文件的路径, 在HTML中导入静态文件,可以直接使用 static 
STATICS_DIRS = [
    os.path.join(BASE_DIR, "static")
]

 

- 全局中的配置文件的解析说明:

  pass

 

自定义相关内容

 pass

 

 

posted @ 2018-10-20 16:16  浮生凉年  阅读(217)  评论(0编辑  收藏  举报