我在index.html
:
<h1>Im an index page.</h1>
{% for post in posts %}
<div>
<h3>{{ post.title }}</h3>
<p>{{ posts.summary }}</p>
</div>
{% endfor %}
但是当我执行它时,我的页面看起来像这样:
答案 0 :(得分:0)
urls.py:
from django.conf.urls import url,include
url(r'^your_appname',include('your_appname.urls')),
在app urls.py中:
from .views import *
url=(r'^$',views.index,name='index')
在models.py中:
class Post(models.Model):
title = models.CharField(max_length=100)
summary = models.CharField(max_length=500)
在views.py中:
from django.shortcuts import render
from .models import *
def inedx(request):
posts = Post.objects.all()
return render(request, 'html_page_location/index.html',{'posts':posts})
如果你这样做,数据将被渲染到你的html模板中。