Skip to content

jungeunlee95/django-basic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

9 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

[TOC]

Python Django ๐Ÿ

postgresql์— db ์ƒ์„ฑ ๋ฐ ๊ณ„์ • ์ƒ์„ฑ

[1] create database djdb;

1560924643198

[2] create user djdb with password 'djdb';

[3] grant all privileges on all tables in schema public to djdb;

1560924696919

[3] data/pg_hba.conf์— ์ ‘๊ทผ ์„ค์ •

vi /cafe24/pgsql/data/pg_hba.conf

1560924852478

1560924873431

[4] ์—ฐ๊ฒฐ ํ™•์ธ

1560924923367

pycharm์—์„œ Django ์‹œ์ž‘ํ•˜๊ธฐ

๐Ÿ“‚๊ตฌ์กฐ

1) ํ”„๋กœ์ ํŠธ 
	๊ฐœ๋ฐœ ๋Œ€์ƒ์ด ๋˜๋Š” ์ „์ฒด ํ”„๋กœ๊ทธ๋žจ์„ ์˜๋ฏธ
	
2) ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜
	ํ”„๋กœ์ ํŠธ๋ฅผ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๊ธฐ๋Šฅ์œผ๋กœ ๋‚˜๋ˆ„์—ˆ์„ ๋•Œ, ํ”„๋กœ์ ํŠธ ํ•˜์œ„์˜ ์—ฌ๋Ÿฌ ์„œ๋ธŒ ํ”„๋กœ๊ทธ๋žจ
	
3) ํ”„๋กœ์ ํŠธ ๋””๋ ‰ํ† ๋ฆฌ์™€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๊ตฌ๋ถ„ํ•ด์„œ ๊ด€๋ฆฌ

4) ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋‹จ์œ„๋กœ ํ”„๋กœ์ ํŠธ๋ฅผ ๊ตฌ์„ฑํ•˜๊ณ  ํ”„๋กœ์ ํŠธ๋ฅผ ๋ชจ์•„ ๋” ํฐ ํ”„๋กœ์ ํŠธ๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๊ณ„์ธต์  ๊ตฌ์กฐ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.

๐Ÿ›ฐ๏ธ ์‹œ์ž‘

[1] pycharm ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ(python_ch3 ํ”„๋กœ์ ํŠธ)

1560922999591

[2] Django ์„ค์น˜

[ํ„ฐ๋ฏธ๋„]

pip install django

1560922904435

[3] ์žฅ๊ณ  ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

[ํ„ฐ๋ฏธ๋„]

django-admin startproject python_ch3

django-admin startproject [python_ch3] โ€‹ โ“

1560922517271

๋ฌธ์ œ์  : ํŒŒ์ด์ฐธ ํ”„๋กœ์ ํŠธ ๋ฐ‘์œผ๋กœ ๋“ค์–ด๊ฐ€์„œ ํ•œ๋‹จ๊ณ„ ๋ฐ‘์œผ๋กœ ๋‚ด๋ ค๊ฐ”์–ด!

1560922941249

[4] ๋””๋ ‰ํ† ๋ฆฌ ์ •๋ฆฌ

pycharm ํ”„๋กœ์ ํŠธ์™€ djangoํ”„๋กœ์ ํŠธ์˜ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ผ์น˜ ์‹œํ‚ค๋Š” ์ž‘์—…!

(๊ทธ๋ƒฅ ํ•œ์นธ์”ฉ ์ƒ์œ„ ํด๋”๋กœ ์˜ฎ๊ธฐ๊ณ  ์‚ญ์ œํ•˜๋ฉด ๋จ)

1560923107012

[5] db(postgresql)์‚ฌ์šฉ : psycopg2 ์„ค์น˜

[ํ„ฐ๋ฏธ๋„]

pip install psycopg2

[6] settings.py ์„ค์ •

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 ๋””๋ ‰ํ† ๋ฆฌ ๋งŒ๋“ค๊ธฐ

1560926525442

[7] django project์˜ ๊ธฐ๋ณธ ๊ด€๋ฆฌ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‚ฌ์šฉํ•˜๋Š” ํ…Œ์ด๋ธ” ์ƒ์„ฑ

[ํ„ฐ๋ฏธ๋„]

python manage.py migrate

1560925438772

[8] django project์˜ ๊ธฐ๋ณธ ๊ด€๋ฆฌ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋กœ๊ทธ์ธ ๊ณ„์ • ์ƒ์„ฑ

๊ด€๋ฆฌ ๊ณ„์ • ์ƒ์„ฑํ•˜๊ธฐ

[ํ„ฐ๋ฏธ๋„]

python manage.py createsuperuser 

[9] server start

[ํ„ฐ๋ฏธ๋„]

python manage.py runserver 0.0.0.0:8888

1560925741149

๐Ÿš Application ์ž‘์—…

[ ์žฅ๊ณ  ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋””์ž์ธ ํŒจํ„ด : MTV ]

1560926233853

[1] application ์ถ”๊ฐ€ํ•˜๊ธฐ

[ํ„ฐ๋ฏธ๋„]

python manage.py startapp helloworld

1560926028419

[2] application ๋“ฑ๋กํ•˜๊ธฐ (settings.py)

INSTALLED_APPS

INSTALLED_APPS = [
    'helloworld',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

[3] views.py์— ๋“ฑ๋ก 1560926746770

def hello(request):
    return render(request, 'hello.html')

[4] urls.py์— path๋“ฑ๋ก 1560926754778

import helloworld.views as helloworl_views

urlpatterns = [
    path('helloworld/', helloworl_views.hello),
    path('admin/', admin.site.urls),
]

[5] templates์— html ๋งŒ๋“ค๊ธฐ 1560926864592

ํ™•์ธ โœ”๏ธ

1560927095862

About

first django chapter ๐ŸŒผ - python_ch3

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published