How to reflect CSS in Django

How to reflect CSS in Django

Here's how to reflect CSS in Django.

environment

Python 3.7.6 Django 3.0.5

Edit setting.py

Write the following code at the bottom of setting.py.

setting.py



#Upper part omitted

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'

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

Add CSS file

Add a static folder and make it as follows

| - webproject
| | - setting.py
| | - urls.py
| - webapp
| | - urls.py
| | - views.py
| - templates
| | - form.html
| - static
| | - css
| | | - style.css
|manage.py

Editing HTML files

Add ``` {% load static%}` `` at the top.

{% 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>WebApp</title>
    <link href="{% static 'css/style.css' %}" rel="stylesheet">
  </head>
  <body>
    <p>Hello World!</p>
  </body>
</html>

Editing CSS files

Make sure it is reflected.

p {
  color: blue;
}

Certainly reflected ^ _ ^

スクリーンショット 2020-04-28 21.33.42.png

Recommended Posts

How to reflect CSS in Django
How to delete expired sessions in Django
How to do Server-Sent Events in Django
How to convert DateTimeField format in Django
How to run some script regularly in Django
How to create a Rest Api in Django
How to develop in Python
How to get multiple model objects randomly in Django
How to upload files in Django generic class view
How to use Decorator in Django and how to make it
How to reference static files in a Django project
How to write custom validations in the Django REST Framework
[Python] How to do PCA in Python
How to handle session in SQLAlchemy
[Django] How to test Form [TDD]
How to use Laravel-like ORM / query builder Orator in Django
How to use classes in Theano
How to write soberly in pandas
How to collect images in Python
Errors related to memcached in django
How to update Spyder in Anaconda
How to check ORM behavior in one file with django
How to update user information when logging in to Django RemoteUserMiddleware
How to use SQLite in Python
[Django] How to give input values in advance with ModelForm
How to convert 0.5 to 1056964608 in one shot
How to generate a query using the IN operator in Django
How to get started with Django
How to kill processes in bulk
How to use Mysql in python
How to wrap C in Python
How to use ChemSpider in Python
How to use PubChem in Python
How to write Django1.9 environment-independent wsgi.py
In Django, how to abbreviate the long displayed string as ....
How to run TensorFlow 1.0 code in 2.0
How to handle Japanese in Python
How to log in to Docker + NGINX
How to authenticate with Django Part 2
How to authenticate with Django Part 3
How to call PyTorch in Julia
[Django] How to read variables / constants defined in an external file
How to deploy a Django app on heroku in just 5 minutes
How to do arithmetic with Django template
[Introduction to Python] How to use class in Python?
How to suppress display error in matplotlib
Django: Migration doesn't reflect model in DB
How to access environment variables in Python
How to dynamically define variables in Python
How to check the version of Django
How to convert csv to tsv in CLI
CSS environment created in 10 minutes using Django
[Itertools.permutations] How to put permutations in Python
How to use Google Test in C
How to implement nested serializer in drf-flex-fields
How to work with BigQuery in Python
How to execute commands in jupyter notebook
How to do'git fetch --tags' in GitPython
How to get a stacktrace in python
How to extract polygon area in Python
How to reassign index in pandas dataframe