美文网首页
Django基础

Django基础

作者: 许卫栋 | 来源:发表于2014-09-27 16:31 被阅读152次

    cd c:/
    django-admin.py startproject XXXX
    cd XXXX
    django-admin.py startapp XXX
    cd XXX
    mkdir templates

    settings.py
    add 'XXX',

    urls.py

    url(r'^index/$','XXX.views.index'), 以index为url后缀

    XXX/viesw.py

    from django.shortcuts import render
    from django.template import loader,Context,Template
    from django.http import HttpResponse
    from django.shortcuts import render_to_response

    def index(req):
    t = loader.get_template('hello.html')
    c = Context({'uname':'wayne'})
    return HttpResponse(t.render(c))

    def index1(req):
    t = Template('<h1>hello {{uname}}</h1>')
    c = Context({'uname':'wayne'})
    return HttpResponse(t.render(c))

    def index2(req):
    return render_to_response('hello.html',{'uname':'wayne'})

    cd XXXX

    python manage.py runserver

    相关文章

      网友评论

          本文标题:Django基础

          本文链接:https://www.haomeiwen.com/subject/ervutttx.html