Python 呈现“的视图”;“一般”;模板应该在哪里(home.html、about.html等)德扬戈

Python 呈现“的视图”;“一般”;模板应该在哪里(home.html、about.html等)德扬戈,python,django,python-3.x,django-views,Python,Django,Python 3.x,Django Views,我有一些模板,比如home.html,about.html,等等,它们是“通用”的 呈现这些视图的视图应位于何处 我不相信把这些观点放在我的项目的应用程序中,因为每一个观点都有一个非常具体的目的。我想到了专门为这些“常规”视图创建一个应用程序,但是这个应用程序应该被称为什么呢?这是一种好的做法吗 另一个解决方案是将视图放在urlconf中,如下所示: from django.contrib import admin from django.urls import path, include f

我有一些模板,比如
home.html
about.html
,等等,它们是“通用”的

呈现这些视图的视图应位于何处

我不相信把这些观点放在我的项目的应用程序中,因为每一个观点都有一个非常具体的目的。我想到了专门为这些“常规”视图创建一个应用程序,但是这个应用程序应该被称为什么呢?这是一种好的做法吗


另一个解决方案是将视图放在urlconf中,如下所示:

from django.contrib import admin
from django.urls import path, include
from django.views.generic import TemplateView

urlpatterns = [
    path('admin/', admin.site.urls),

    path('', TemplateView.as_view(template_name = 'pages/home.html'), name = 'home'), # here
    ...
]
但这是良好实践的替代方案吗?
有更好的选择吗?

只需将它们放在您的全球应用程序中即可。假设我的Django项目名为
project\u name
,我有一个名为
tasks
的应用程序。下面是我要做的:

~/projects/projects_name/

project_name/       # project dir (the one which django-admin.py creates)
    ...
  settings/         # settings for different environments, see below
    __init__.py
    ...
  views.py         # Put here global views (home, etc.)
  urls.py
  wsgi.py
  static/             # site-specific static files
  templates/          # site-specific templates
    project_name/
      home.html
      about.html
  tests/              # site-specific tests (mostly in-browser ones)
...


tasks/
    ...
    static/             # tasks app-specific static files
    templates/          # tasks app-specific templates

将它们放在你的基础应用程序中,因为它们可能会在任何地方使用。基础应用程序是什么?我没有那个应用程序。但这是一个良好的做法吗?我在项目名称中没有看到views.py…是的。您可以创建它,甚至可以创建一个models.py。是否有相关文档?看起来很有趣。。