zoukankan      html  css  js  c++  java
  • [django]Django输出页面方式的补充

    1、直接输出 -- HTTPResponse

    helloworld.py

    from django.utils.httpwrappers import HttpResponse
    def index(request):
     
    return HTTPResponse('''<html><head></head><body>Hello world</body></html>''');
    def out(request):
     response 
    = HttpResponse(mimetype='text/csv')
     response[
    'Content-Disposition'= 'attachment; filename=1.txt'
     response.write(
    'abcdef')
     
    return response

    urls.py

    urlpatterns 
    = patterns('',
        (r
    '^$''test.helloworld.index'),
    )

    2. MTC -- render_to_response

    helloworld.py (view)

    #coding=utf-8
    from django.core.extensions import render_to_response
    def index(request):
            
    return render_to_response('helloworld', {'params': {'a':1'b':2} } )

    helloworld.html (template)

    <html>
    <body>
      
    <table>
      {% for key in params%}
      
    <tr><td> {{key}} </td><td> {{params.key}} </td></tr>
      {% endfor %}
      
    </table>
    </body>
    </html>

    以上是One Piece总结的,下面我再补充一个,其实这个是第一种的变样

    3、从template加载

    from django.template import loader, Context
    = loader.get_template('common/post_note.htx')
    = Context({'action': request.path , 'title': consts.ADD_TOPIC})
    return HttpResponse(t.render(c))


     

  • 相关阅读:
    插入排序
    JavaMail学习笔记
    Struts2的工作原理
    我的快速排序
    截取字符串,只截取前N个字节的字符
    修改MyEclipse8.6中的Servlet.java模板
    Java类装载的过程及原理介绍
    cmd检查jdk的版本
    快速排序
    flash 侦测人的面部
  • 原文地址:https://www.cnblogs.com/maplye/p/496239.html
Copyright © 2011-2022 走看看