Search

Django for personal reference

I created a page to organize the parts I often found confusing and easy to forget when I first started learning Django, such as project creation and configuration, so that I can quickly refer back to it and refresh my memory whenever needed.

Django Quickstart Guide (Personal Reference)

1. Virtual Environment

Create

Mac/Linux
python3 -m venv venv source venv/bin/activate
Bash
복사
python3 -m venv venv is the command used to create a virtual environment. The last part, venv, is the name of the virtual environment, and it’s common practice to simply name it venv. If you want to name the environment devchoi, you can run python -m venv devchoi instead.
The second command, source venv/bin/activate, is used to activate the virtual environment.
Windows
python -m venv venv venv\Scripts\activate
Bash
복사
It’s common practice to place the virtual environment inside the Git project root folder (/venv).
For learning purposes or small side projects, it is common to place the virtual environment either directly inside the project folder or in a dedicated folder like venvs/. However, keep in mind that the location of the virtual environment can vary depending on the size and purpose of the project.
It is strongly recommended to add the virtual environment folder to your .gitignore file. Virtual environments should not be uploaded to Git, as they are unnecessary and may cause compatibility issues across different systems. Instead, share dependencies using a requirements.txt file.
django-repo/ ← Django repo for Git ├── venvs/ │ ├── projectA-env/ ← Virtual env for project A │ └── projectB-env/ ← Virtual env for project B ├── projectA/ ← Actual project A └── projectB/ ← Actual project B
Bash
복사
Here is an example .gitignore file that you can refer
# Virtual environments venvs/ # Python cache __pycache__/ *.pyc *.pyo *.pyd # Django default database db.sqlite3 # IDE / editor settings .vscode/ .idea/
Bash
복사

2. Install Django / Packages

(1) If requirements.txt does NOT exist

pip install django
Bash
복사

(2) If requirements.txt exists

pip install -r requirements.txt
Bash
복사
After installing new packages, always update the file
pip freeze > requirements.txt
Bash
복사

3. Create Django Project

django-admin startproject config .
Bash
복사
config/ : project settings
manage.py : project management
In the command django-admin startproject config ., the word config represents the project name (that is, the name of the directory to be created), while the dot (.) at the end indicates that the project should be created inside the current directory. The name config is not mandatory—you can freely choose any project name you like. For example, you could run django-admin startproject myblog . or django-admin startproject shop ., and it would work in the same way.
The reason config is commonly used is that this directory contains files such as settings.py, urls.py, asgi.py, and wsgi.py, which are mostly related to configuration. For this reason, many tutorials and guides adopt config as a conventional name, since it’s intuitive and descriptive.
In summary, config is a commonly used naming convention, but not a requirement. You are free to name the project directory according to the nature of your project, such as myproject, backend, or core.

4. Run Development Server

# Mac/Linux python3 manage.py runserver # Windows python manage.py runserver
Bash
복사
Default URL → http://127.0.0.1:8000/

5. Create & Register App

python manage.py startapp myapp
Bash
복사
Add to INSTALLED_APPS in settings.py
INSTALLED_APPS = [ ..., 'myapp', ]
Python
복사

6. Database Migration

Initialize
python manage.py migrate
Bash
복사
Apply model changes
python manage.py makemigrations python manage.py migrate
Bash
복사

7. Create Admin User

python manage.py createsuperuser
Bash
복사

8. OS-Specific Command Differences

Category
Mac/Linux
Windows
Create venv
python3 -m venv venv
python -m venv venv
Activate venv
source venv/bin/activate
venv\Scripts\activate
Run server
python3 manage.py runserver
python manage.py runserver
With this guide, you can quickly recall what to do when starting a new project or when working with an existing project that has requirements.txt.

Django Admin Superuser Creation Guide

1. Activate Virtual Environment

Mac / Linux
source venv/bin/activate
Bash
복사
Windows
venv\Scripts\activate
Bash
복사

2. Create Superuser

Mac / Linux
python3 manage.py createsuperuser
Bash
복사
Windows
python manage.py createsuperuser
Bash
복사

3. Enter Account Information

When prompted, provide the following details:
Username: admin ← choose your own username Email address: admin@example.com Password: ******** Password (again): ******** Superuser created successfully.
Plain Text
복사
Note : When typing your password, nothing will appear on the screen. This is normal—it is still being recorded.