[PYTHON] Django's basic memorandum

A reminder of the settings and commands you need to get started with Django

Project creation

django-admin startproject [project-name] .

Change settings

[project-name]/settings.py


TIME_ZONE = 'Asia/Tokyo'
LANGUAGE_CODE = 'ja'
#When publishing a static file
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
#Add public host
ALLOWED_HOSTS = ['127.0.0.1', [host]]
##Example
ALLOWED_HOSTS = ['127.0.0.1', '.pythonanywhere.com']

Database creation

python manage.py migrate

Web server start

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

Create a new application

python manage.py startapp [app-name]

Add new application to settings

[project-name]/settings.py



INSTALLED_APPS = [
    ...
    'blog.apps.BlogConfig', #App class name of the added app
]

Create migration to create table from Model

python manage.py makemigrations [app-name]

Migration execution

python manage.py migrate [app-name]

Access to management screen

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

Create Super User

python manage.py createsuperuser

.gitignore Base uses 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/

##Customize from here
# My pipenv
myvenv/

#VS code
.vscode/
##Customize up to here

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

Recommended Posts

Django's basic memorandum
Linux basic command memorandum
Python basic memorandum part 2
python memorandum super basic
Work memorandum (pymongo) Part 1. Basic operation
Matplotlib memorandum
linux memorandum
jinja2 memorandum
Numpy [Basic]
Python memorandum
Command memorandum
Python Memorandum 2
plotly memorandum
Slackbot memorandum (1)
Memorandum MetaTrader 5
[Linux/LPIC] Memorandum
A memorandum of understanding about django's QueryDict
ShellScript memorandum
pip memorandum
Python memorandum
Basic commands
pydoc memorandum
python memorandum
Pandas memorandum
python memorandum
DjangoGirls memorandum
Command memorandum
Python memorandum
pandas memorandum
python memorandum
Django's ImageField
Python memorandum
Memorandum for me ③ Basic file editing using vi