Mémorandum de base de Django

Un mémorandum des paramètres et commandes nécessaires pour démarrer Django

Création de projet

django-admin startproject [project-name] .

Modifier les paramètres

[project-name]/settings.py


TIME_ZONE = 'Asia/Tokyo'
LANGUAGE_CODE = 'ja'
#Lors de la publication d'un fichier statique
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
#Ajouter un hôte public
ALLOWED_HOSTS = ['127.0.0.1', [host]]
##Exemple
ALLOWED_HOSTS = ['127.0.0.1', '.pythonanywhere.com']

Création de base de données

python manage.py migrate

Démarrage du serveur Web

python manage.py runserver [host]:[port]

Créer une nouvelle application

python manage.py startapp [app-name]

Ajouter une nouvelle application aux paramètres

[project-name]/settings.py



INSTALLED_APPS = [
    ...
    'blog.apps.BlogConfig', #Nom de la classe d'application de l'application ajoutée
]

Créer une migration pour créer une table à partir du modèle

python manage.py makemigrations [app-name]

Exécution de la migration

python manage.py migrate [app-name]

Accès à l'écran de gestion

http://[host]:[port]/admin

Créer un super utilisateur

python manage.py createsuperuser

.gitignore La base utilise https://www.gitignore.io

.gitignore


# Created by https://www.gitignore.io/api/django
# Edit at https://www.gitignore.io/?templates=django

### Django ###
*.log
*.pot
*.pyc
__pycache__/
local_settings.py
db.sqlite3
db.sqlite3-journal
media

# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
# in your Git repository. Update and uncomment the following line accordingly.
# <django-project-name>/staticfiles/

### Django.Python Stack ###
# Byte-compiled / optimized / DLL files
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
#  Usually these files are written by a python script from a template
#  before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# pyenv
.python-version

# pipenv
#   According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
#   However, in case of collaboration, if having platform-specific dependencies or dependencies
#   having no cross-platform support, pipenv may install dependencies that don't work, or not
#   install all needed dependencies.
#Pipfile.lock

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

##Personnalisez à partir d'ici
# My pipenv
myvenv/

#VS code
.vscode/
##Personnalisez jusqu'à ici

# End of https://www.gitignore.io/api/django

Recommended Posts

Mémorandum de base de Django
Mémorandum de base Python partie 2
mémorandum python super basique
Mémorandum de travail (pymongo) Partie 1. Fonctionnement de base
Mémorandum Matplotlib
mémorandum Linux
mémorandum jinja2
Numpy [basique]
Mémorandum Python
Mémorandum de commandement
Mémorandum Python 2
mémorandum complot
Mémorandum Slackbot (1)
Mémorandum MetaTrader5
Mémorandum sur le QueryDict de Django
Mémorandum ShellScript
mémorandum pip
Mémorandum Python
Commandes de base
mémorandum pydoc
mémorandum python
Mémorandum de Pandas
mémorandum python
Mémorandum DjangoGirls
Mémorandum de commandement
Mémorandum Python
mémorandum pandas
mémorandum python
ImageField de Django
Mémorandum Python
Mémorandum pour moi ③ Édition de fichiers de base avec vi