[TOC]
[1] create database djdb;
[2] create user djdb with password 'djdb';
[3] grant all privileges on all tables in schema public to djdb;
[3] data/pg_hba.conf
์ ์ ๊ทผ ์ค์
vi /cafe24/pgsql/data/pg_hba.conf
[4] ์ฐ๊ฒฐ ํ์ธ
1) ํ๋ก์ ํธ
๊ฐ๋ฐ ๋์์ด ๋๋ ์ ์ฒด ํ๋ก๊ทธ๋จ์ ์๋ฏธ
2) ์ ํ๋ฆฌ์ผ์ด์
ํ๋ก์ ํธ๋ฅผ ์ฌ๋ฌ ๊ฐ์ ๊ธฐ๋ฅ์ผ๋ก ๋๋์์ ๋, ํ๋ก์ ํธ ํ์์ ์ฌ๋ฌ ์๋ธ ํ๋ก๊ทธ๋จ
3) ํ๋ก์ ํธ ๋๋ ํ ๋ฆฌ์ ์ ํ๋ฆฌ์ผ์ด์
๋๋ ํ ๋ฆฌ๋ฅผ ๊ตฌ๋ถํด์ ๊ด๋ฆฌ
4) ์ ํ๋ฆฌ์ผ์ด์
๋จ์๋ก ํ๋ก์ ํธ๋ฅผ ๊ตฌ์ฑํ๊ณ ํ๋ก์ ํธ๋ฅผ ๋ชจ์ ๋ ํฐ ํ๋ก์ ํธ๋ฅผ ๊ตฌ์ฑํ๋ ๊ณ์ธต์ ๊ตฌ์กฐ๊ฐ ๊ฐ๋ฅํ๋ค.
[ํฐ๋ฏธ๋]
pip install django
[ํฐ๋ฏธ๋]
django-admin startproject python_ch3
django-admin startproject [python_ch3]
โ โ
๋ฌธ์ ์ : ํ์ด์ฐธ ํ๋ก์ ํธ ๋ฐ์ผ๋ก ๋ค์ด๊ฐ์ ํ๋จ๊ณ ๋ฐ์ผ๋ก ๋ด๋ ค๊ฐ์ด!
pycharm ํ๋ก์ ํธ์ djangoํ๋ก์ ํธ์ ๋๋ ํ ๋ฆฌ๋ฅผ ์ผ์น ์ํค๋ ์์ !
(๊ทธ๋ฅ ํ์นธ์ฉ ์์ ํด๋๋ก ์ฎ๊ธฐ๊ณ ์ญ์ ํ๋ฉด ๋จ)
[ํฐ๋ฏธ๋]
pip install psycopg2
1) TIME_ZONE ์ค์
TIME_ZONE = 'Asia/Seoul'
2) DATABASES ์ค์
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'djdb',
'USER': 'djdb',
'PASSWORD': 'djdb',
'HOST': '192.168.1.52',
'PORT': 5432,
}
}
3) TEMPLATES DIRS(๋๋ ํ ๋ฆฌ)์ค์
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# ํ๋ก์ ํธ์ ์์น!
TEMPLATES = [
{
...
'DIRS': [os.path.join(BASE_DIR, 'templates')],
...
}
]
4) templates ๋๋ ํ ๋ฆฌ ๋ง๋ค๊ธฐ
[ํฐ๋ฏธ๋]
python manage.py migrate
๊ด๋ฆฌ ๊ณ์ ์์ฑํ๊ธฐ
[ํฐ๋ฏธ๋]
python manage.py createsuperuser
[ํฐ๋ฏธ๋]
python manage.py runserver 0.0.0.0:8888
[ํฐ๋ฏธ๋]
python manage.py startapp helloworld
INSTALLED_APPS
INSTALLED_APPS = [
'helloworld',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
def hello(request):
return render(request, 'hello.html')
import helloworld.views as helloworl_views
urlpatterns = [
path('helloworld/', helloworl_views.hello),
path('admin/', admin.site.urls),
]