我是 mongodb 和 django 的新手。我在 django 中设置了所有的models
和。urls.py
但是是时候在视图页面上检索数据库的信息了。我的数据库看起来像:
{
"_id": {
"$oid": "52221778633a610c58c131e6"
},
"text": "just",
"tags": [
"mongo",
"django"
],
"comments": [],
"title": "hello" }
数据库名称:事件集合名称:polls_post
我urls.py
的样子:
from django.conf.urls.defaults import patterns, include, url
from django.views.generic import ListView, DetailView
from polls.models import Post
urlpatterns = patterns('',
url(r'^time/$','polls.views.current_datetime'),
url(r'^events/$','polls.views.events'),
)
我的views.py
样子:
from django.http import HttpResponse
import datetime
def current_datetime(request):
now = datetime.datetime.now()
html = "<html><body>It is now %s.</body></html>" % now
return HttpResponse(html)
def events(request):
html = "<html><body>title is:<h1></h1></body></html>"
return HttpResponse(html)
那么,我们将如何从数据库中获取文本、标题和评论,以便将其显示在网页上?