Django parameter settings

Source: Internet
Author: User

This note uses Django-1.8.6, other versions do not

After the Django project is created, it is necessary to configure the parameters first, commonly used configurations include: database configuration , template configuration , static file configuration ,session configuration, etc.

1, database configuration. Locate the Databases field in settings.py to configure the following:
1DATABASES = {2     'default': {3         'ENGINE':'Django.db.backends.mysql',#the MySQL database is configured here4         'HOST':'Database server IP',5         'PORT': 3306,#database port, MySQL default port is 33066         'NAME':'Database name',7         'USER':'Database user name',8         'PASSWORD':'user-corresponding password',9     }Ten}

2. A template has been configured by default in Django-1.8.6, as follows. If you need to modify the template path, simply modify the dirs line
1TEMPLATES = [2     {3         'Backend':'django.template.backends.django.DjangoTemplates',4          'DIRS': [Os.path.join (Base_dir, 'templates' )]      #to configure multiple paths, you can use commas to separate them5         ,6         'App_dirs': True,7         'OPTIONS': {8             'context_processors': [9                 'Django.template.context_processors.debug',Ten                 'django.template.context_processors.request', One                 'Django.contrib.auth.context_processors.auth', A                 'django.contrib.messages.context_processors.messages', -             ], -         }, the     }, -]

3, configure the static file path, where the static file is configured in the project root directory, the Staticfiles_dirs field is not the default, you need to add
1 staticfiles_dirs = [2     os.path.join (base_dir,'static' ) )3 ]

4. Session Timeout setting
1 session_expire_at_browser_close = True  # SESSION Timeout When browser is off 2  3 session_cookie_age = 60*30   # set SESSION time-out, unit is seconds



Django parameter settings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.