[PYTHON] Django ~ settings.py edition ~

Introduction

This article was written to make a note of the settings.py settings in Django.

Set the time zone

First, let's set the time zone. If you open "settings.py" and scroll to the gar

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

I will find this part, so I will change it a little.

LANGUAGE_CODE = 'ja'

TIME_ZONE = 'Asia/Tokyo'

By changing in this way, you can adjust to Japan time.

App registration

Scroll a little from the top of "settings.py" and find "INSTALLED_APPS" elsewhere. We will add it here to register the application configuration information. Here, the app name is "app".

INSTALLED_APPS = [
    'app.apps.AppConfig',
]

Add it like this at the very beginning or end of the parentheses. Be careful not to forget the last comma.

Template registration

If you go a little further down from "INSTALLED_APPS" you will find something called "TEMPLATES". Register "templates" to store the HTML file here.

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
            ],
        },
    },
]

It should look like this. I will register in "DIRS" here.

'DIRS': [os.path.join(BASE_DIR, 'templates')],

If you can put it in this way, you're done.

Registration of static directory

We will register the "static" directory where CSS, JavaScript, images, etc. are stored. By default, it is not held, so I will add it at the end.

STATICFILES_DIRS = (
    [os.path.join(BASE_DIR, 'static')]
)

It's perfect if you add it like this.

Finally

This time, I have summarized what to write in "settings.py". I plan to have more dates in the future. Previous article Procedure to create application with Django with Pycharm ~ Preparation ~

Recommended Posts

Django ~ settings.py edition ~
Django settings.py SECRET_KEY error
Django
Introduction to Python Django (2) Mac Edition
django update
Django note 4
Django memorandum
django search
Django installation
Django Summary
Django test
Django # 2 (template)
Django Note 5
Django hands-on
Touch django
django notes
Django Summary
Django basics
Django Shoho
Django defaults
Django + Docker
Django Glossary
Django search
Install Django
Django: References
Django Note 1
Django note 3
Django note 2
Django startup
Django notes
Django NullCharField