Django 平面页面的视图?
我使用以下内容来确定与索引页面匹配的模式上的模板,其中我根据 AJAX 请求来确定要加载的模板:
def home(request):
if request.is_ajax():
template = "ajax.html"
else:
template = "index.html"
entries = posts.objects.all()[:10]
return render_to_response(template, {'posts' : entries}, context_instance=RequestContext(request))
但是,我没有任何有关 view.py 中提到的平面页面的信息,我怎样才能对平面页面的模板进行类似的 request.is_ajax() 检查?
谢谢!
I use the following to determine the template on a pattern that matches the index page, in which I determine which template to load based on if it's an AJAX request:
def home(request):
if request.is_ajax():
template = "ajax.html"
else:
template = "index.html"
entries = posts.objects.all()[:10]
return render_to_response(template, {'posts' : entries}, context_instance=RequestContext(request))
However, I don't have anything regarding flatpages mentioned in my views.py, how can I do a similar request.is_ajax() check for the templates of flatpages?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
知道了!
urls.py
视图.py:
Got it!
urls.py
views.py: