unknown 3 月之前
父節點
當前提交
92d6608a81

二進制
courses/django_kind/sitewomen/sitewomen/__pycache__/__init__.cpython-312.pyc


二進制
courses/django_kind/sitewomen/sitewomen/__pycache__/settings.cpython-312.pyc


二進制
courses/django_kind/sitewomen/sitewomen/__pycache__/urls.cpython-312.pyc


二進制
courses/django_kind/sitewomen/sitewomen/__pycache__/wsgi.cpython-312.pyc


二進制
courses/django_kind/sitewomen/women/__pycache__/__init__.cpython-312.pyc


二進制
courses/django_kind/sitewomen/women/__pycache__/admin.cpython-312.pyc


二進制
courses/django_kind/sitewomen/women/__pycache__/apps.cpython-312.pyc


二進制
courses/django_kind/sitewomen/women/__pycache__/models.cpython-312.pyc


二進制
courses/django_kind/sitewomen/women/__pycache__/urls.cpython-312.pyc


二進制
courses/django_kind/sitewomen/women/__pycache__/views.cpython-312.pyc


+ 12 - 0
courses/django_kind/sitewomen/women/converters.py

@@ -0,0 +1,12 @@
+
+
+class FourDigitYearConverter:
+    regex = "[0-9]{4}"
+
+    def to_python(self, value):
+        return int(value)
+    
+
+    def to_url(self, value):
+        return "%04d" % value
+    

二進制
courses/django_kind/sitewomen/women/migrations/__pycache__/__init__.cpython-312.pyc


+ 8 - 2
courses/django_kind/sitewomen/women/urls.py

@@ -1,8 +1,14 @@
-from django.urls import path
+from django.urls import path, re_path, register_converter
 from . import views
+from . import converters
 
 
+register_converter(converters.FourDigitYearConverter, "year4")
+
 urlpatterns = [
     path('', views.index), # http://127.0.0.1:8000
-    path('cats/', views.categories), # http://127.0.0.1:8000/cats/
+    path('cats/<int:cat_id>/', views.categories), # http://127.0.0.1:8000/cats/1/
+    path('cats/<slug:cat_slug>/', views.categories_by_slug), # http://127.0.0.1:8000/cats/asdfad/
+    # re_path(r"^archive/(?P<year>[0-9]{4})", views.archive),
+    path('archive/<year4:year>', views.archive),
 ]

+ 10 - 2
courses/django_kind/sitewomen/women/views.py

@@ -8,5 +8,13 @@ def index(request): # HttRequest
     return HttpResponse("Страница приложения women.")
 
 
-def categories(request):
-    return HttpResponse("<h1>Статьи по категориям</h1>")
+def categories(request, cat_id):
+    return HttpResponse(f"<h1>Статьи по категориям</h1><p>id: {cat_id}</p>")
+
+
+def categories_by_slug(request, cat_slug):
+    return HttpResponse(f"<h1>Статьи по категориям</h1><p>slug: {cat_slug}</p>")
+
+
+def archive(request, year):
+    return HttpResponse(f"<h1>Архив по годам</h1><p>{year}</p>")