-
[Python] url tag 사용하기Python/Django 2021. 12. 14. 00:43
# client side {% for room in rooms %} <h3> # rooms = path namespace # detail = path name # room.pk = path argument <a href="{% url 'rooms:detail' room.pk %}"> {{room.name}} / ${{room.price}} </a> </h3> {% endfor %}
# rooms.urls.py urlpatterns = [ path("<int:pk>/", views.room_detail, name='detail') ]
# config.urls.py urlpatterns = [ path("admin/", admin.site.urls), path("", include("core.urls", namespace="core")), path("rooms/", include("rooms.urls", namespace="rooms")), ]
'Python > Django' 카테고리의 다른 글
[Python] CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False. (0) 2021.12.14 [Python] TypeError: 'ManyRelatedManager' object is not iterable (0) 2021.12.14 [Python] 'Specifying a namespace in include() without providing an app_name ' dj (0) 2021.12.14 [Python] VSCode에서 Django 템플릿 오토 포매팅하기 (0) 2021.12.13 [Python] Django Class Based Views 정리 사이트 (0) 2021.12.11