When to create a new app (with startapp) in Django?

前端 未结 8 2009
余生分开走
余生分开走 2020-12-12 15:44

I\'ve googled around for this, but I still have trouble relating to what Django defines as \"apps\".

Should I create a new app for each piece of functionality in a

8条回答
  •  旧时难觅i
    2020-12-12 16:28

    An 'app' could be many different things, it all really comes down to taste. For example, let's say you are building a blog. Your app could be the entire blog, or you could have an 'admin' app, a 'site' app for all of the public views, an 'rss' app, a 'services' app so developers can interface with the blog in their own ways, etc.

    I personally would make the blog itself the app, and break out the functionality within it. The blog could then be reused rather easily in other websites.

    The nice thing about Django is that it will recognize any models.py file within any level of your directory tree as a file containing Django models. So breaking your functionality out into smaller 'sub apps' within an 'app' itself won't make anything more difficult.

提交回复
热议问题