Python Django CSS reflected

Premise

Since the method of reflecting css was ambiguous, I will describe it.

【environment】 os python3.7.3 Django3.0.5

Application name: sns

【file organization】 sns | - snsproject | | - setting.py | | - urls.py | - snsapp | | - urls.py | | - views.py | - templates | | - sns | | | - index.html | - static | | - css | | | - style.css |manage.py

Main subject

I will implement it immediately.

settings.py


・ ・ ・
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'sns', #Postscript
]
・ ・ ・
TEMPLATES = [
    {
        'DIRS': [
            os.path.join(BASE_DIR, 'templates'), #Postscript
        ],
            ],
        },
    },
]
・ ・ ・

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    [
        os.path.join(BASE_DIR, "static"), #Postscript
    ]
)

Next, edit templates / index.html.

index.html


{% load static %} 
<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>sns</title>
    <link href="{% static 'css/stylesheet.css' %}" rel="stylesheet">
  </head>
  <body>
  </body>
</html>

The CSS is now reflected.

Recommended Posts

Python Django CSS reflected
Python Django Tutorial (5)
Python Django Tutorial (8)
Python Django Tutorial (6)
Python Django Tutorial (7)
Python Django tutorial tutorial
Python Django Tutorial (3)
Python Django Tutorial (4)
Django 1.11 started with Python3.6
Python-compress Django css / js
Python Django tutorial summary
Django python web framework
Django Python shift table
Try Debian + Python 3.4 + django1.7 ...
[Personal notes] Python, Django
Do Django with CodeStar (Python3.6.8, Django2.2.9)
Introduction to Python Django (2) Win
Do Django with CodeStar (Python3.8, Django2.1.15)
Python3 + Django ~ Mac ~ with Apache
Create ToDo List [Python Django]
Getting Started with Python Django (1)
Getting Started with Python Django (3)
Install Python 3.7 and Django 3.0 (CentOS)
GAE + python + Django addictive story
Getting Started with Python Django (6)
Python Django Tutorial Cheat Sheet
Getting Started with Python Django (5)
Django authentication features aren't reflected well
Python
Python practice_Virtual environment setup ~ Django installation
CSS parsing with cssutils in Python
Create new application use python, django
Django
python + django + scikit-learn + mecab (2) on heroku
Run python3 Django1.9 with mod_wsgi (deploy)
Install Python framework django using pip
Introduction to Python Django (2) Mac Edition
Migrate Django applications running on Python 2.7 to Python 3.5
CSS environment created in 10 minutes using Django
I have a question! (Python, django) Easy
CentOS 6.4 with Python 2.7.3 with Apache with mod_wsgi and Django
Python execution server construction (Python + uWSGI + Django + Nginx)
Edit Django shift table HTML and CSS
[Python] Introduce UIKit3 to your Django project