After some django reset initialization routine work

Reset Configuration

1. Execute the following code to create a django project pt_edu:

django-admin startproject pt_edu

 

 

 

 

 2. Create a package config folder, create two files in the config py package folder, respectively develop.py and product.py:

 

 3. The following code was added manage.py, asgi.py, wsgi.py replaced:

# Os.environ.setdefault ( 'the DJANGO_SETTINGS_MODULE', 'pt_edu.settings') 
# by the environment variable PROJECT_PROFILE to develop or product, so that different loading configurations django 
Profile = os.environ.get ( ' PROJECT_PROFILE ' , ' develop ' )
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pt_edu.config.%s' % profile)

manage.py as follows:

#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


DEF main ():
     # os.environ.setdefault ( 'the DJANGO_SETTINGS_MODULE', 'pt_edu.settings') 
    # by the environment variable PROJECT_PROFILE to develop or product, so that different loading configurations django 
    Profile = os.environ.get ( ' PROJECT_PROFILE ' , ' Develop ' )
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pt_edu.config.%s' % profile)
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

asgi.py as follows:

"""
ASGI config for pt_edu project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
"""

import the

from django.core.asgi import get_asgi_application

# Os.environ.setdefault ( 'the DJANGO_SETTINGS_MODULE', 'pt_edu.settings') 
# by the environment variable PROJECT_PROFILE to develop or product, so that different loading configurations django 
Profile = os.environ.get ( ' PROJECT_PROFILE ' , ' develop ' )
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pt_edu.config.%s' % profile)

application = get_asgi_application()

wsgi.py as follows:

"""
WSGI config for pt_edu project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
"""

import the

from django.core.wsgi import get_wsgi_application

# Os.environ.setdefault ( 'the DJANGO_SETTINGS_MODULE', 'pt_edu.settings') 
# by the environment variable PROJECT_PROFILE to develop or product, so that different loading configurations django 
Profile = os.environ.get ( ' PROJECT_PROFILE ' , ' develop ' )
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pt_edu.config.%s' % profile)

application = get_wsgi_application()

4. Load develop test environment default configuration, the production environment need to set environment variables start:

[Set Environment Variables]
windows:  set PROJECT_PROFILE=product
PowerShell: $env:PROJECT_PROFILE="product"
linux: export PROJECT_PROFILE=product

5.develop.py reference to the following configuration:

from ..settings import *

DEBUG = True

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'django_db',
        'USER': 'root',
        'PASSWORD': '123456',
        'HOST': '127.0.0.1',
        'PORT': '3306',
    }
}

6.product.py reference to the following configuration (the file can not be added to the inside git):

Develop.py with it.

Guess you like

Origin www.cnblogs.com/jiangxiaobo/p/12584567.html