기존에는 의존성이 강해서 주소변경시 아래와 같이 변경을 많이 해야 했다.
urls.py
, header.html
, 총 2개를 변경해 주어야만 했다.
기존주소 news
-> watcha
로 바뀌어야 할 때
urls.py
urlpatterns = [
#url(r'^news/$', news)
url(r'^watcha/$', news)
]
header.html
<!-- <li><a href="/news">News</a></li> -->
<li><a href="/watcha">News</a></li>
이렇게 매번 바꿔줘야만 했다. 작업이 비효율적이다.
그래서 Django에서는 아래와 같은 Template Language
를 사용할수가 있다.
urls.py에 name으로 값을 정해주면 header.html을 바뀔때마다 바꿀 필요가 없다
urls.py
#url(r'^news/$', news)
url(r'^news/$', news, name="news")
header.html
<!-- <li><a href="/news">News</a></li> -->
<li><a href="{% url "news"%}">News</a></li>
기본적으로 shell을 불러오면 settings
나 model
를 import시켜줘야 했음
이런 불편한 점을 해소하기 위해 django_extensions shell_plus
를 사용하면 됨
python wpsblog/manage.py shell_plus
로 사용한다.
alias msp="python wpsblog/manage.py shell_plus"
로 간편하게 사용
shell_plus
를 사용하면 기본적으로 아래것들이 import가 됨
# Shell Plus Model Imports
from django.contrib.admin.models import LogEntry
from django.contrib.auth.models import Group, Permission, User
from django.contrib.contenttypes.models import ContentType
from django.contrib.sessions.models import Session
# 현재까지 만들어진 model들
from wpsblog.models.naver_post import NaverPost
from wpsblog.models.posts import Post
# Shell Plus Django Imports
from django.conf import settings
from django.core.urlresolvers import reverse
from django.utils import timezone
from django.db.models import Avg, Count, F, Max, Min, Sum, Q, Prefetch, Case, When
from django.db import transaction
from django.core.cache import cache