Я работаю над сайтом в настоящее время (сначала одно соло) и пошел для движения, делают индексную страницу. Я пытался применить django лучшие методы, когда я иду, так естественно я иду, ищут это, но не мог реальный стандарт в отношении этого.
Я видел, что люди создают приложения для служения этой цели, названной различными вещами (основной, домой, misc), и видел views.py в корне проекта. Я действительно просто ищу то, что большинство там делают для этого.
Индексная страница не статична, так как я хочу обнаружить, если пользователь зарегистрирован и такой.
Спасибо.
If all of your dynamic content is handled in the template (for example, if it's just simple checking if a user is present on the request), then I recommend using a generic view, specificially the direct to template view:
urlpatterns = patterns('django.views.generic.simple',
(r'^$', 'direct_to_template', {'template': 'index.html'}),
)
If you want to add a few more bits of information to the template context, there is another argument, extra_context
, that you can pass to the generic view to include it:
extra_context = {
'foo': 'bar',
# etc
}
urlpatterns = patterns('django.views.generic.simple',
(r'^$', 'direct_to_template', {'template': 'index.html', 'extra_context': extra_context }),
)
I tend to create a views.py
in the root of the project where I keep the index
view.