Django中的网站和应用程式有什么区别? [英] What is the difference between a site and an app in Django?

查看:143
本文介绍了Django中的网站和应用程式有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道一个网站可以有很多应用,但是我看到的所有例子都有这个网站叫做mysite。我认为该网站将是您的网站的名称,例如StackOverflow。



你会这样做,然后有认证,问题和搜索这样的应用程序?或者你真的只需要一个名为mysite的网站叫做StackOverflow?

解决方案

Django实际上有3个概念: p>


  • 项目(我认为这是你所呼叫的网站):这是包含所有的应用程序他们共享一个常见的运行时调用,可以互相参考。


  • 应用:这是一组视图,模型和模板。应用程序经常被设计成可以插入另一个项目。


  • 站点:您可以根据正在访问的网站(即:URL)。这样,相同的App可以根据用户是否访问过StackOverflow.com或RackOverflow.com(或任何IT目标版本将被调用)进行自定义,即使它是相同的代码库这是处理请求。




如何排列这些是由您的项目决定的。在复杂的情况下,您可以执行以下操作:

 项目:StackOverflowProject 
应用程序:Web版本
站点: StackOverflow.com
网站:RackOverflow.com
应用:XML API版本
网站:StackOverflow.com
网站:RackOverflow.com
常见的非应用设置,库,auth,etc

或者,对于想要利用开源插件的更简单的项目: / p>

 项目:StackOverflowProject 
应用程序:Stackoverflow
(没有具体使用的网站功能...只是一个网站)
应用程序:插件TinyMCE编辑器与图像上传
(没有具体使用的网站功能)

除了需要一个项目,至少有一个应用程序,安排非常灵活;您可以适应最适合帮助抽象和管理部署的复杂性(或简单性)。


I know a site can have many apps but all the examples I see have the site called "mysite". I figured the site would be the name of your site, like StackOverflow for example.

Would you do that and then have apps like "authentication", "questions", and "search"? Or would you really just have a site called mysite with one app called StackOverflow?

解决方案

Django actually has 3 concepts here:

  • Project (I think this is what you're calling site): This is the directory that contains all the apps. They share a common runtime invocation and can refer to each other.

  • App: This is a set of views, models, and templates. Apps are often designed so they can be plugged into another project.

  • Site: You can designate different behaviour for an app based on the site (ie: URL) being visited. This way, the same "App" can customize itself based on whether or not the user has visited 'StackOverflow.com' or 'RackOverflow.com' (or whatever the IT-targeted version will be called), even though it's the same codebase that's handling the request.

How you arrange these is really up to your project. In a complicated case, you might do:

Project: StackOverflowProject
    App: Web Version
        Site: StackOverflow.com
        Site: RackOverflow.com
    App: XML API Version
        Site: StackOverflow.com
        Site: RackOverflow.com
    Common non-app settings, libraries, auth, etc

Or, for a simpler project that wants to leverage an open-source plugin:

Project: StackOverflowProject
    App: Stackoverflow
        (No specific use of the sites feature... it's just one site)
    App: Plug-in TinyMCE editor with image upload
        (No specific use of the sites feature)

Aside from the fact that there needs to be a Project, and at least one app, the arrangement is very flexible; you can adapt however suits best to help abstract and manage the complexity (or simplicity) of your deployment.

这篇关于Django中的网站和应用程式有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆