使用Django从桌子显示 [英] Display from a table using Django

查看:140
本文介绍了使用Django从桌子显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你可以给我一小段代码,我们在Django中显示数据。.....



请指点一个代码进入views.py和template / index.html来忽略表.............



谢谢....

解决方案

阅读Django教程。它以4个部分显示了这个框架的基础知识。



关于你的问题,一个很快的例子。



在views.py:

  def显示(请求):
返回render_to_response('template.tmpl',{'obj':models.Book.objects.all ()})

在models.py:




author = models.CharField(max_length = 20)
title = models.CharField(max_length = 40)
publication_year = models.IntegerField()

在template.tmpl:

 < table> 
< tr>
< th>作者< / th>
< th> title< / th>
< th>出版年份< / th>
< / tr>
{%for b in obj%}
< tr>
< td> {{b.author}}< / td>
< td> {{b.title}}< / td>
< td> {{b.publication_year}}< / td>
< / tr>
{%endfor%}
< / table>


Can you please give me a small piece of code where we display data from a table if any in Django.....

Please point me to a code that goes into views.py and template/index.html to diaply the table.............

Thanks....

解决方案

Read the Django tutorial. It shows, in 4 parts, the basics of this framework.

As for your question, a very quick example.

In views.py:

def display(request):
  return render_to_response('template.tmpl', {'obj': models.Book.objects.all()})

In models.py:

class Book(models.Model):
  author = models.CharField(max_length = 20)
  title = models.CharField(max_length = 40)
  publication_year = models.IntegerField()

In template.tmpl:

<table>
<tr>
  <th>author</th>
  <th>title</th>
  <th>publication year</th>
</tr>
{% for b in obj %}
<tr>
  <td>{{ b.author }}</td>
  <td>{{ b.title }}</td>
  <td>{{ b.publication_year }}</td>
</tr>
{% endfor %}
</table>

这篇关于使用Django从桌子显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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