问题描述
我很喜欢django,有一个关于组织意见的问题。 manage.py startapp
在我的应用文件夹中创建一个 views.py
。但是, django-admin.py startproject< name>
不会在< project_name> /< project_name>中创建相应的views.py文件。
文件夹。 我觉得直觉具有与特定应用不符的全局视图。例如,登录页面将和应该独立于我创建的任何应用程序(与django auth应用程序相关联)。那么在我可以定义这些视图的< project_name> /< project_name>
文件夹中创建另一个views.py是否有意义?
(只是想在经历的djangoers之前继续运行)。
谢谢。
- 您可以随时随地编写全局视图。它可以是任何文件名(我使用,global_views.py)
- 我曾经编写一个全局来覆盖/自定义默认框架应用程序,如自定义身份验证后端和自定义网站。
- 更好地创建自定义应用并编写所有全局视图。
I'm new to django and had a question regarding organizing views. manage.py startapp
creates a views.py
in my app folder. But django-admin.py startproject <name>
does not create a corresponding views.py file in the <project_name>/<project_name>
folder.
I find it intuitive to have global views which do not correspond to a particular app. For example, a login page would and should be independent of any app that I create (its associated with the django auth app). So, would it make sense to create another views.py in the <project_name>/<project_name>
folder where I can define such views?
(Just wanted to run it by experienced djangoers before I proceed.)
Thanks.
- You can write your global views anywhere. it can be in any file name (I use, global_views.py)
- I used to write a global to overrride/customize the default framework apps like custom authentication backend and custom sites.
- Better to create a custom app and write all the global views.
这篇关于Django视图架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!