简体   繁体   English

用于博客的 Django 项目结构

[英]Django project structure for blog

Im new to django and im folowing many tutorial about django and every one of them have a different style and technique.我是 django 的新手,我遵循了许多关于 django 的教程,每个教程都有不同的风格和技术。 my main focus is to structure my project for my django blog project.我的主要重点是为我的 django 博客项目构建我的项目。 please help me to figure it out请帮我弄清楚

Here are my question Should i seperate the app for the example post, comment, categorie,tag, meta descriptions or just create the blog app and have all that model view in one app or i need to create the post, comment, categorie, tag, meta descriptions, and adding the frontend app to handle the views and url.这是我的问题我应该为示例帖子、评论、类别、标签、元描述单独应用程序,还是只创建博客应用程序并在一个应用程序中拥有所有模型视图,或者我需要创建帖子、评论、类别、标签、元描述,并添加前端应用程序来处理视图和 url。

if i have to seperate the the app that i mention above should the administrator for the dashboard area so the user can add post or delete in the app it self or i have to create the dashboard/administrator app.如果我必须分离我上面提到的应用程序应该是仪表板区域的管理员,以便用户可以自行在应用程序中添加帖子或删除,或者我必须创建仪表板/管理员应用程序。

Should i seperate the project for dashboard administrator with public page.我应该将仪表板管理员的项目与公共页面分开吗? or should their in same project but in deferent app.或者他们应该在同一个项目中但在不同的应用程序中。

i have done many schenario but one of the one i thing the best is.我做过很多场景,但我最擅长的场景之一是。 like this but i need aloot of comment about it像这样,但我需要很多评论

blog
--blog
--frontend
---- models.py model i leave it empty
---- views.py i focus handel the view of all blog app in here
---- urls.py urls so it make it easy to read and manage
--administrator
---- models.py model i leave it empty
---- views.py easy to set the validator decorator and anything
---- urls.py make the url easy to manage site/administrator if have to add post so it can be site/administrator/add-post
--posts
---- models.py
---- views.py
---- etc except urls.py
--categorie
---- models.py
---- views.py
---- etc except urls.py
--tag
---- models.py
---- views.py
---- etc except urls.py
--comment
---- models.py
---- views.py
---- etc except urls.py
--manage.py
--db.sqlite3

An app is a submodule of the project, it must be independent and focus on one task.应用程序是项目的子模块,它必须是独立的并专注于一项任务。 So unless your project is very small, you should split it into multiple apps dependent on the logical parts of the blog: posts, comments, tags, users, categories, ... By dividing the project into various apps you avoid having huge files and gain in simplicity, reusability and elegance.因此,除非您的项目非常小,否则您应该根据博客的逻辑部分将其拆分为多个应用程序:帖子、评论、标签、用户、类别……获得简单性、可重用性和优雅性。 Each app should contain its own models, views, forms and urls.每个应用程序都应该包含自己的模型、视图、表单和 URL。 Having a unique urls file doesn't make things easier, because you need to hard code the full path and it all gets chaotic quickly without organization.拥有一个唯一的 urls 文件并不会让事情变得更容易,因为您需要对完整路径进行硬编码,并且在没有组织的情况下很快就会变得混乱。 You should construct your frontend by putting each view in the right app and the associated templates in a unique directory.您应该通过将每个视图放在正确的应用程序中并将关联的模板放在一个唯一的目录中来构建您的前端。 For administration, you can take advantage of the Django Admin that comes out of the box and simply include an admin.py file in each app (read the documentation for details), but this type of administration should only be accessible to superusers.对于管理,您可以利用开箱即用的 Django Admin,只需在每个应用程序中包含一个admin.py文件(阅读文档了解详细信息),但这种类型的管理只能由超级用户访问。 To allow normal users to make changes, you have to create views and templates in the associated apps.要允许普通用户进行更改,您必须在关联的应用程序中创建视图和模板。 So compared to your current scheme I would remove the administrator and frontend app, I would create a urls.py file and a admin.py file for each app.因此,与您当前的方案相比,我将删除administratorfrontend应用程序,我将为每个应用程序创建一个urls.py文件和一个admin.py文件。 For templates you can create a folder in each app or use a top level folder for all of them.对于模板,您可以在每个应用程序中创建一个文件夹或为所有应用程序使用顶级文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM