This tells Python that the string is a “raw string” – its contents should not interpret backslashes.
In normal Python strings, backslashes are used for escaping special characters – such as in the string “\n
”, which is a one-character string containing a newline. When you add the r
to make it a raw string, Python does not apply its backslash escaping – so, “r'\n'
” is a two-character string containing a literal backslash and a lowercase “n”.
Django는 URL 패턴을 검사하기 전에 들어오는 모든 URL 앞에 슬래시를 제거합니다.
즉 /hello/ 라고 치면 제일 처음 / 는 의미가 없어져버리는 것임.
그리고 제일 뒤에 $ 달러사인이 없어버리면 모든
^hello/ 라고 쳤을 경우 뒤에 모든 문자열이 매칭이 되어버림.
꼭 뒤에 $ 를 붙이도록 하자.
후행슬래쉬는 무조건 필요하다. APPEND_SLASH
설정이 되어있을경우는
없어도 된다.
또한 중요하게 생각해야 한다는 것은. hello라는 Function을 전달했다는 것이 포인트이다.
이것은 Python의 핵심기능중 하나임. (함수포인터라고 생각하면 편할듯...)
[장고에서 자주사용하는 정규표현식]
Symbol | Matches |
---|---|
. (dot) | Any single character |
\d | Any single digit |
[A-Z] | Any character between A and Z (uppercase) |
[a-z] | Any character between a and z (lowercase) |
[A-Za-z] | Any character between a and z (case-insensitive) |
+ | One or more of the previous expression (e.g., \d+ matches one or more digits) |
[^/]+ | One or more characters until (and not including) a forward slash |
? | Zero or one of the previous expression (e.g., \d? matches zero or one digits) |
* | Zero or more of the previous expression (e.g., \d* matches zero, one or more than one digit) |
{1,3} | Between one and three (inclusive) of the previous expression (e.g., \d{1,3} matches one, two or three digits) |
'Python > Django' 카테고리의 다른 글
[Django] RestFrameWork 튜토리얼 - 1. 직렬화 (0) | 2017.03.10 |
---|---|
[Django] 템플릿 태그와 필터 (0) | 2017.03.08 |
[Django] 템플릿 (0) | 2017.03.08 |
[Django] Dynamic URL (0) | 2017.03.08 |
[Django] VIew와 URL conf (0) | 2017.03.07 |