Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.

Commit

Permalink
URL Dispatcher와 정규 표현식
Browse files Browse the repository at this point in the history
  • Loading branch information
askcompany-kr committed Feb 3, 2020
1 parent efb3ec0 commit e7eee32
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions blog1/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from . import views

app_name = 'blog1' # URL Reverse에서 namespace역할을 하게 됩니다.

urlpatterns = [
path('', views.post_list, name='post_list'),
Expand Down
22 changes: 20 additions & 2 deletions instagram/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
from django.urls import path, re_path
from django.urls import path, re_path, register_converter

from . import views


class YearConverter:
regex = r"20\d{2}"

def to_python(self, value):
return int(value)

def to_url(self, value):
return str(value)


register_converter(YearConverter, 'year')

app_name = 'instagram' # URL Reverse에서 namespace역할을 하게 됩니다.

urlpatterns = [
path('', views.post_list),
path('', views.post_list, name='post_list'),
path('<int:pk>/', views.post_detail),
# path('archives/<int:year>/', views.archives_year),
# re_path(r'archives/(?P<year>20\d{2})/', views.archives_year),
path('archives/<year:year>/', views.archives_year),
# re_path(r'(?P<pk>\d+)/$', views.post_detail),
]
4 changes: 4 additions & 0 deletions instagram/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ def post_detail(request: HttpRequest, pk: int) -> HttpResponse:
response.write("Hello World")
response.write("Hello World")
return response


def archives_year(request, year):
return HttpResponse(f"{year}년 archives")

0 comments on commit e7eee32

Please sign in to comment.