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" >
< div data-gb-custom-block data-tag = "csrf_token" ></ div >
</ form >
hidden κ°μΌλ‘ csrf token
μ΄ μΆκ°λμ΄ μλ κ² νμΈ κ°λ₯
Curl λ‘ κ°λ¨ν μμ² λ 리기
Copy curl -X GET http://chloecodes1.pythonanywhere.com/community/
Telnet μ¬μ©ν΄λ³΄κΈ°
μ€μΉ
Copy sudo apt-get install telnetd
request λ 리기
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 = "
<div data-gb-custom-block data-tag=" url " data-0 = 'articles:index' ></ div >"> ... </ a >
< a href = "<div data-gb-custom-block data-tag=" url " data-0 = 'articles:delete' ></ div >"> ... </ a >
<form class="form-inline" action="<div data-gb-custom-block data-tag="url" data-0='articles:search'></div>" 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