Django在网页上看到两个视图 [英] Django two views on a webpage

查看:225
本文介绍了Django在网页上看到两个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,谢谢你提前,

我非常喜欢Django / Python noobie。我只需要指导,不一定是答案。我已经阅读了所有有关的文件,我似乎找不到我正在努力做的简明例子。

I am very much a Django/Python noobie. I just need guidance, not necessarily answers. I have read all the pertinent documentation and I can't seem to find a concise example of what I am trying to do.

我有两个视图,一个是表单,另一个是列出数据库表中包含的数据的视图。我试图在用户转到URLS.py文件中列出的一个URL的同一网页页面上显示这两个视图。我相信这是可能的,我同样确信我缺少一些基本的东西。

I have two views, one is a form and the other is a view that lists data contained in a database table. I am trying to display both these views on the same webpage page that is called by the user going to one URL listed in the URLS.py file. I am sure this is possible, I am equally sure I am missing something basic.

感谢您的帮助。

dp

推荐答案

我通常会尝试以小件形式定义我的观点。例如,表单可能是这样的:

I usually try and define my views in small pieces. For example, the form might be something like this:

<!-- form.html -->
<form><input type="submit"/></form>

,模型列表是这样的:

<!-- listing.html -->
<ul>
{% for item in items %}
<li>Item {{ item.name }}</li>
{% endfor %}
</ul>

然后,只是的页面如下所示:

Then, the page that is just the form would look like this:

<!-- form_page.html -->
<html><body>
{% include "form.html" %}
</body></html>

只有列表的页面:

<!-- listing_page.html -->
<html><body>
{% include "listing.html" %}
</body></html>

和两个页面:

<!-- both_page.html -->
<html><body>
{% include "form.html" %}
{% include "listing.html" %}
</body></html>

这是一个非常简化的例子,但希望您能得到想法。

This is a very simplified example, but hopefully you get the idea.

这篇关于Django在网页上看到两个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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