处理多字Django模型的最佳命名约定?
最好的命名约定是什么?例如,带有多个单词的Django模型的url和模板名称 实例处理多字Django模型的最佳命名约定?,django,Django,最好的命名约定是什么?例如,带有多个单词的Django模型的url和模板名称 实例 yetanothermodel=yetanothermodel() 还有另一个模型=YetAnotherModel() Url名称 'yetanothermodel\u detail' “还有另一款车型的细节” 模板名称 'yetanothermodel\u detail.html' “还有另一个模型\u detail.html” 这是你个人的选择。但是如果你在一个团队中工作,我会说你应该应用Python编码标准
yetanothermodel=yetanothermodel()
还有另一个模型=YetAnotherModel()
'yetanothermodel\u detail'
“还有另一款车型的细节”
'yetanothermodel\u detail.html'
“还有另一个模型\u detail.html”
这是你个人的选择。但是如果你在一个团队中工作,我会说你应该应用Python编码标准;这样,团队的所有成员都使用相同的过程和命名约定来编写代码 在这种情况下:
yet_another_model = YetAnotherModel()
应为小写,下划线分隔。使用驼峰式大小写命名约定
及
Url名称应被视为or,小写字母用ux(下划线)分隔
模板:
虽然没有为模板定义命名约定,但我将命名视为函数名。所以在这些情况下,我选择小写加下划线的单词分隔。
我还将模板保存在django应用程序中(有时,我会有一个模板目录,其中每个应用程序名都有一个目录)
我还将CRUD类型粘贴在文件名的末尾
例如:
<app_div>/user_profile.html
<app_dir>/user_profile_update.html
<app_dir>/user_profile_view.html
<app_dir>/user_profile_delete.html
/user\u profile.html
/用户_profile_update.html
/用户_profile_view.html
/用户_profile_delete.html
这也是我的首选,但它与基于类的视图的默认模板名称不太一致。我已经更新了答案,将它们也包括在问题中。YetAnotherModel()基于类的视图中的默认模板(如果没有指定)是什么?是yetanothermodel_detail.html吗?还是另一个模型detail.html?它是yetanothermodel\u detail.html
。通用视图使用YetAnotherModel.\u meta.model\u name
,名称中不包含下划线:
<app_div>/user_profile.html
<app_dir>/user_profile_update.html
<app_dir>/user_profile_view.html
<app_dir>/user_profile_delete.html