1. DB
DB ์ด๊ธฐํ
migration
file ํ์ธ
Copy $ python manage.py showmigrations
๋ค์ migrations
๋ง๋ค๊ธฐ
Copy $ python manage.py makemigrations
๋์๋๋ SQL
๋ฌธ ์ถ๋ ฅ
Copy $ python manage.py sqlmigrate articles 0001
[app_label] [migration_name]
BEGIN ;
--
-- Create model Article
--
CREATE TABLE "articles_article" ( "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "title" varchar ( 140 ) NOT NULL, "content" text NOT NULL, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL );
COMMIT ;
migrate
ํ๊ธฐ
Copy $ python manage.py migrate
[app_label] [migration_name]
create()
์์ฑ์ ์ํด์๋ ์๋์ ๊ฐ์ด๋ ํ ์ ์๋ค!
Copy Article . objects . create (title = '์ ๋ชฉ' , content = '๋ด์ฉ' )
fd
Copy article = Article (title = '์ ๋ชฉ' , content = '๋ด์ฉ' )
article . save ()
IntegrityError
: This exception is raised when the relational integrity of the data is affected.
2. GET
& POST
method
GET
ํน์ ๋ฆฌ์์ค์ ํ์
<a>
tag <form>
tag ๋ฐ ๋ธ๋ผ์ฐ์ ์์ ์ฃผ์์ฐฝ์ ๋ณด๋ด๋ ์์ฒญ ๋ฑ
URL
์ ํ์ฉ (querystring) ํ์ฌ data๋ฅผ ์ ์กํจ
ํฌ๊ธฐ ์ ํ & ๋ณด์ ์ด์๊ฐ ์์
POST
ํน์ ๋ฆฌ์์ค์ ์ ์ถ (์๋ฒ์ ์ํ ๋ณํ)
๋ณดํต HTML Form์
ํตํด ์๋ฒ์ ์ ์กํ๋ฉฐ, ์๋ฒ์ ๋ณ๊ฒฝ์ฌํญ์ ๋ง๋ฆ
HTTP ์์ฒญ ๋ฉ์์ง์ body
์ data๋ฅผ ์ ์กํจ
HTTP (Hyper Text Markup Language)
Resource๋ฅผ ๊ฐ์ ธ์ฌ ์ ์๋๋ก ํด์ฃผ๋ protocol
์น์์ ์ด๋ฃจ์ด์ง๋ ๋ชจ๋ ๊ตํ์ ๊ธฐ์ด
Request
URL (Uniform Resource Locators)
Web์์ ์ ํด์ง ์ ์ผํ ์์์ ์ฃผ์
ํ๋กํ ์ฝ :// ๋๋ฉ์ธ: ํฌํธ/ ๊ฒฝ๋ก(path)/?ํ๋ผ๋ฏธํฐ#์ต์ปค
Response
views.py ์์
Copy def create ( request ):
article = Article ()
article . title = request . POST . get ( 'title' )
article . content = request . POST . get ( 'content' )
article . save ()
return redirect ( f '/articles/ { article.pk } /' )
CSRF
token ์ถ๊ฐํ๊ธฐ
Copy <form action="/articles/create/" method="POST">
{% csrf_token %}
</form>
hidden ๊ฐ์ผ๋ก csrf token
์ด ์ถ๊ฐ๋์ด ์๋ ๊ฒ ํ์ธ ๊ฐ๋ฅ
Curl ๋ก ๊ฐ๋จํ ์์ฒญ ๋ ๋ฆฌ๊ธฐ
Copy $ curl -X GET http://chloecodes1.pythonanywhere.com/community/
Telnet ์ฌ์ฉํด๋ณด๊ธฐ
์ค์น
Copy $ sudo apt-get install telnetd
request ๋ ๋ฆฌ๊ธฐ
Copy $ telnet google.com 80
3. app_name
์ง์ ํ๊ธฐ
urls.py
Copy from django . urls import path
from . import views
app_name = 'articles'
urlpatterns = [
# /articles/
path ( '' , views.index, name = 'index' ),
path ( 'new/' , views.new, name = 'new' ),
path ( 'create/' ,views.create, name = 'create' ),
path ( '<int:pk>/' ,views.detail, name = 'detail' ),
path ( 'delete/<int:pk>/' ,views.delete, name = 'delete' ),
path ( 'edit/<int:pk>/' , views.edit, name = 'edit' ),
path ( 'update/<int:pk>/' , views.update, name = 'update' ),
]
views.py
Copy from django . shortcuts import render , redirect , get_object_or_404
from . models import Article
# Create your views here.
def index ( request ):
articles = Article . objects . all ()
context = {
'articles' : articles
}
return render (request, 'articles/index.html' , context)
def new ( request ):
return render (request, 'articles/new.html' )
def create ( request ):
article = Article ()
article . title = request . POST . get ( 'title' )
article . content = request . POST . get ( 'content' )
article . save ()
# return redirect(f'/articles/{article.pk}/')
return redirect ( 'articles:detail' , article.pk)
def detail ( request , pk ):
article = Article . objects . get (id = pk)
context = {
'article' : article
}
return render (request, 'articles/detail.html' , context)
def delete ( request , pk ):
article = Article . objects . get (id = pk)
article . delete ()
# return redirect(f'/articles/')
return redirect ( 'articles:index' )
def edit ( request , pk ):
article = get_object_or_404 (Article, id = pk)
context = {
'article' : article
}
return render (request, 'articles/edit.html' , context)
def update ( request , pk ):
article = Article . objects . get (id = pk)
article . title = request . POST . get ( 'title' )
article . content = request . POST . get ( 'content' )
article . save ()
return redirect ( f '/articles/ { article.pk } /' )
In html
Copy <a class="navbar-brand" href="{% url 'articles:index' %}"> ... </a>
<a href="{% url 'articles:delete' article.pk %}"> ... </a>
<form class="form-inline" action="{% url 'articles:search' %}" method="POST"> ... </form>
4. get_object_or_404
article = Article.objects.get(id=pk)
get( ) ์ ๊ฐ์ด ์์ผ๋ฉด error๋ฅผ ๋์
๋จ ํ๋๋ฅผ returnํ๋ method
๊ทธ๋์ ์ฌ์ฉํ๋ ๊ฒ
Copy from django . shortcuts import render , redirect , get_object_or_404
...
article = get_object_or_404 (Article, id = pk)
5. Static files
settings.py
Copy # servering ๋๋ URL ์์ ๋ถ์
STATIC_URL = '/static/'
# app directory ๊ฐ ์๋ static ํด๋ ์ง์
STATICFILES_DIRS = [
os . path . join (BASE_DIR, 'static' )
]
+
Traceroute
TraceRoute
- Linux / TRACERT
- Windows
์ง์ ๋ ํธ์คํธ์ ๋๋ฌํ ๋๊น์ง ํต๊ณผํ๋ ๊ฒฝ๋ก์ ์ ๋ณด์ ๊ฐ ๊ฒฝ๋ก์์์ ์ง์ฐ ์๊ฐ์ ์ถ์ ํ๋ ๋ช
๋ น์ด๋ค, ์ฝ๊ฒ ๊ฒฝ๋ก ์ถ์ ํด์ด๋ผ๊ณ ๋ณผ ์ ์๋ค (ICMP์ ์ฌ์ฉํ๋ค!)
์ง์ ๋ ํธ์คํธ์ ๋๋ฌํ ๋๊น์ง ํต๊ณผํ๋ ๊ฒฝ๋ก์ ์ ๋ณด ์ ๊ฐ ๊ฒฝ๋ก์์์ ์ง์ฐ ์๊ฐ ์ ์ถ์ ํ๋ ๋คํธ์ํฌ ๋ช
๋ น์ด๋ก ํน์ ์ฌ์ดํธ์ ์ ์์ด ๋์ง ์๊ฑฐ๋ ์ง์ฐ์ด ์๋ ๊ฒฝ์ฐ ์ด๋์์ ๋ณ๋ชฉ์ด ๋ฐ์ํ๋์ง๋ฅผ ์์๋ณด๋๋ฐ ์ ์ฉํจ.
์ ์์ด ๋๋ ๊ฐ ๊ฒฝ๋ก๋ฅผ ์ฒดํฌํ์ฌ ์ด๋ ๊ฒฝ๋ก(Routing) ๋ฅผ ๊ฑฐ์ณ ์ ์์ด ๋๊ณ , ์ด๋ ๊ตฌ๊ฐ ์์ ์ผ๋ง๋งํผ ์ ์๋ ์ง์ฐ์ด ์๋์ง, ๊ทธ๋ฆฌ๊ณ ์ด๋์์ ํจํท์ด ์ค์ง ๋๋์ง๋ฅผ ํ์ธํ ์ ์์
๋จ, ์๊ฐ๋/๋ด๋ถ ํธ๋ํฝ/์๋ฒ ์ํ ๋ฑ์ ๋ง์ ์ํฅ์ ๋ฐ์ ๊ฐ์ด ๋ฌ๋ผ์ง ์ ์์ผ๋ฏ๋ก ๋ฐ๋ณต ํ์ธ์ด ํ์ํ๋ค!
Install traceroute
Copy $ sudo apt-get install traceroute
Use traceroute
Copy $ traceroute www.google.com
traceroute to www.google.com (172.217.31.164), 30 hops max, 60 byte packets
1 _gateway (172.30.1.254) 5.195 ms 5.127 ms 5.105 ms
2 220.78.3.1 (220.78.3.1) 5.071 ms * *
3 125.141.249.21 (125.141.249.21) 5.364 ms 5.308 ms 5.262 ms
4 * * *
5 * * *
6 112.174.73.178 (112.174.73.178) 6.510 ms 112.174.47.162 ( 112.174.47.162 ) 5.301 ms 112.174.73.178 ( 112.174.73.178 ) 4.858 ms
7 74.125.52.16 (74.125.52.16) 31.913 ms 31.801 ms 33.951 ms
8 108.170.242.129 (108.170.242.129) 36.142 ms 108.170.242.97 ( 108.170.242.97 ) 34.386 ms 34.811 ms
9 209.85.253.109 (209.85.253.109) 36.711 ms 36.555 ms 36.483 ms
10 nrt12s22-in-f4.1e100.net (172.217.31.164) 34.998 ms 33.267 ms 32.844 ms
MVC Pattern