在何处存储非静态Django主页的my index.html和索引视图
我正在创建一个Django项目,目前有3个应用程序产品、问题和选项-我已经让它们按照我的意愿单独/一起运行,并且正在使用名称空间,并将下面给出的my urls.py包含在我的URL中在何处存储非静态Django主页的my index.html和索引视图,django,django-templates,django-views,Django,Django Templates,Django Views,我正在创建一个Django项目,目前有3个应用程序产品、问题和选项-我已经让它们按照我的意愿单独/一起运行,并且正在使用名称空间,并将下面给出的my urls.py包含在我的URL中 ### urls.py from django.conf.urls import patterns, include, url from django.contrib import admin from django.views.generic import TemplateView admin.autodisc
### urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.views.generic import TemplateView
admin.autodiscover()
urlpatterns = patterns('',
url(r'^products/', include('products.urls', namespace='products')),
url(r'^questions/', include('questions.urls', namespace='questions')),
url(r'^choices/', include('choices.urls', namespace='choices')),
url(r'^admin/', include(admin.site.urls)),
)
现在,我希望添加一个可在localhost:8000/上访问的索引页,它将允许我访问创建的所有模型。我对我的观点很满意
## views.py
from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.views import generic
from products.models import Product
from questions.models import Question
from choices.models import Choice
class IndexView(generic.ListView):
template_name = 'index.html'
context_object_name = 'latest_product_list'
def get_queryset(self):
return Product.objects.all()
def get_context_data(self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
context['questions'] = Question.objects.all()
context['choices'] = Choice.objects.all()
return context
我想知道的是,URL.py条目、views.py定位和index.html位置的最合理组合是什么,以允许我在登录页上显示我的模型组合
谢谢
Matt创建另一个应用程序,我倾向于将其命名为home。这样,您的家庭应用程序就可以从产品、问题和选择中导入模型 应用程序布局 像其他应用程序一样包含您的主页URL,但不要使用前缀
url(r'^', include('home.urls', namespace='home')),
创建另一个应用程序,我倾向于将其命名为home。这样,您的家庭应用程序就可以从产品、问题和选择中导入模型 应用程序布局 像其他应用程序一样包含您的主页URL,但不要使用前缀
url(r'^', include('home.urls', namespace='home')),
感谢这一点-似乎是明智的,并已设法让它工作,几乎完全使用这个答案有模板在home/templates/home/index.html,但除此之外-确切。干杯感谢这一点-似乎是明智的,并已设法让它工作,几乎完全使用这个答案有模板在home/templates/home/index.html,但除此之外-确切。干杯