diff --git a/src/django-master/comments/urls.py b/src/django-master/comments/urls.py index 7df3fab..090779f 100644 --- a/src/django-master/comments/urls.py +++ b/src/django-master/comments/urls.py @@ -1,11 +1,28 @@ +# 导入Django的URL路径配置模块 from django.urls import path +# 导入当前应用(comments)的视图模块(views.py),用于关联URL和视图逻辑 from . import views +# 定义应用命名空间:在模板或反向解析URL时,需通过「app_name:URL名称」的格式定位(如comments:postcomment) +# 作用:避免不同应用间URL名称冲突 app_name = "comments" + +# URL路由列表:配置URL路径与视图的映射关系 urlpatterns = [ + # 评论提交URL:处理用户对特定文章的评论提交请求 path( - 'article//postcomment', + # URL路径规则: + # - 'article/':固定路径前缀,标识与文章相关的操作 + # - '</':动态路径参数,接收整数类型的文章ID(用于指定评论所属文章) + # - 'postcomment':固定路径后缀,标识“提交评论”的操作 + 'article/</postcomment', + + # 关联的视图:调用views.py中的CommentPostView类视图的as_view()方法(类视图需转为视图函数) + # 该视图负责处理评论提交的业务逻辑(如数据验证、保存评论等) views.CommentPostView.as_view(), - name='postcomment'), -] + + # URL名称:用于反向解析(如在模板或代码中通过name='postcomment'生成URL) + name='postcomment' + ), +] \ No newline at end of file