사용자의 request를 장고가 실행하는 알고리즘:
- 사용한 "root URLconf" 모듈을 정한다. (settings.py의 ROOT_URLCONF 변수에서 해당 프로젝트의 최상단의 url 정보파일이 있는 파일명을 명시해준다.)
- 장고는 "root URLconf" 파일을 불러들여(로드), 파일 안의 urlpatterns 변수를 찾는다. (django.urls.path(), django.urls.re_path())
- 사용자의 request는 장고의 HttpRequest라는 인스턴스로 전달이 됨. HttpRequest 인스턴스의 속성에는 "path_info"가 있음(HttpRequest.path_info)
![](https://velog.velcdn.com/images%2Fmuchogusto%2Fpost%2Ff8c680cb-02f6-4951-8b2a-6c48bd54245d%2Fimage.png)
"2번"에서 확인한 urlpatterns 안에 있는 url과 일치하는 지 찾는다.
- 한번 url패턴이 일치하면, 장고는 url패턴과 매칭된 뷰/함수 등을 실행시킨다.
![](https://velog.velcdn.com/images%2Fmuchogusto%2Fpost%2F0df3f78b-0537-466c-b68e-3e6e957c9f32%2Fimage.png)
- 만약 어떠한 팬턴과도 일치하지 않으면, 예외가 발생한다.
예시들:
![](https://velog.velcdn.com/images%2Fmuchogusto%2Fpost%2F9880a8ab-a05b-40d4-ae00-114c466dcd78%2Fimage.png)
![](https://velog.velcdn.com/images%2Fmuchogusto%2Fpost%2F483208cd-c4cc-41e9-b431-46d4bdf0e343%2Fimage.png)
URLconf는 url만 찾는다. method는 고려하지 않는다.
The URLconf doesn’t look at the request method. In other words, all request methods – POST, GET, HEAD, etc. – will be routed to the same function for the same URL.
![](https://velog.velcdn.com/images%2Fmuchogusto%2Fpost%2F96295c1d-8a78-40ac-bea5-70609079b31a%2Fimage.png)
![](https://velog.velcdn.com/images%2Fmuchogusto%2Fpost%2F0289f443-656e-4f20-866f-81ee40d19e74%2Fimage.png)
![](https://velog.velcdn.com/images%2Fmuchogusto%2Fpost%2F7d2e902a-0c2a-40ab-8567-98ddd78c27e1%2Fimage.png)
Reference