python类render_template()的实例源码

views.py 文件源码 项目:Flask_Blog 作者: sugarguo 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def edit():
    site_info = site_get()
    article_id = request.args.get('article_id',0)
    temp_dict = {}
    packet_dict = {}
    packet_list = Packet.query.filter_by().all()
    if packet_list is not None:
        for temp in packet_list:
            temp_dict = temp.__dict__
            del temp_dict["_sa_instance_state"]
            packet_dict[str(temp_dict['id'])] = temp_dict['packet_name']
            #packet_dict = dict( packet_dict.items() + tempdict.items() )

    if article_id != 0:
        article = Article.query.filter_by(id = article_id).first()
        #print article
        if article is not None:
            article = article.__dict__
            title = article['title']
            packet_id = article['packet_id']
            show = article['show']
            body = article['body']

    return render_template('admin/edit.html', **locals())
views.py 文件源码 项目:Flask_Blog 作者: sugarguo 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def outputjson():
    site_info = site_get()
    tempdict = {}
    tempjson = "["
    info_list = Article.query.filter_by().all()
    for item in info_list:
        tempdict = item.__dict__
        del tempdict["_sa_instance_state"]
        value = json.dumps(tempdict,cls=CJsonEncoder)
        tempjson += value + ",\n"
    tempjson = tempjson[:-2] + "]"

    filename = 'page_list_'+str(time.strftime("%Y%m%d"))+'.txt'  
    output = open(filename,'w')  
    output.write(tempjson)  
    output.close()  

    flash(u'?????????????')
    return render_template('admin/output.html', **locals())
templating.py 文件源码 项目:Flask_Blog 作者: sugarguo 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_escaping(self):
        text = '<p>Hello World!'
        app = flask.Flask(__name__)
        @app.route('/')
        def index():
            return flask.render_template('escaping_template.html', text=text,
                                         html=flask.Markup(text))
        lines = app.test_client().get('/').data.splitlines()
        self.assert_equal(lines, [
            b'&lt;p&gt;Hello World!',
            b'<p>Hello World!',
            b'<p>Hello World!',
            b'<p>Hello World!',
            b'&lt;p&gt;Hello World!',
            b'<p>Hello World!'
        ])
signals.py 文件源码 项目:Flask_Blog 作者: sugarguo 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_template_rendered(self):
        app = flask.Flask(__name__)

        @app.route('/')
        def index():
            return flask.render_template('simple_template.html', whiskey=42)

        recorded = []
        def record(sender, template, context):
            recorded.append((template, context))

        flask.template_rendered.connect(record, app)
        try:
            app.test_client().get('/')
            self.assert_equal(len(recorded), 1)
            template, context = recorded[0]
            self.assert_equal(template.name, 'simple_template.html')
            self.assert_equal(context['whiskey'], 42)
        finally:
            flask.template_rendered.disconnect(record, app)
regression.py 文件源码 项目:Flask_Blog 作者: sugarguo 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_memory_consumption(self):
        app = flask.Flask(__name__)
        @app.route('/')
        def index():
            return flask.render_template('simple_template.html', whiskey=42)

        def fire():
            with app.test_client() as c:
                rv = c.get('/')
                self.assert_equal(rv.status_code, 200)
                self.assert_equal(rv.data, b'<h1>42</h1>')

        # Trigger caches
        fire()

        # This test only works on CPython 2.7.
        if sys.version_info >= (2, 7) and \
                not hasattr(sys, 'pypy_translation_info'):
            with self.assert_no_leak():
                for x in range(10):
                    fire()
letters.py 文件源码 项目:margy 作者: opentower 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def home():
    return render_template('home.html')
letters.py 文件源码 项目:margy 作者: opentower 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def newletter():
    return render_template('upload.html')
letters.py 文件源码 项目:margy 作者: opentower 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def deliver():
    return render_template('deliver.html')
letters.py 文件源码 项目:margy 作者: opentower 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def too_big(error):
    return render_template('toobig.html'), 413
letters.py 文件源码 项目:margy 作者: opentower 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def instructions():
    return render_template('quick.html')
letters.py 文件源码 项目:margy 作者: opentower 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def questions():
    return render_template('faq.html')
letters.py 文件源码 项目:margy 作者: opentower 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def whitelist():
    with io.open('static/whitelist.txt', 'r', encoding="utf-8") as f: #gets the contents of whitelist.txt so they can be displayed
        data = f.read().replace('@', ' [at] ').replace('.', ' [dot] ')
    return render_template('whitelist.html',data=data)
letters.py 文件源码 项目:margy 作者: opentower 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def thanks():
    return render_template('thanks.html')
letters.py 文件源码 项目:margy 作者: opentower 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def credits():
    return render_template('credits.html')
letters.py 文件源码 项目:margy 作者: opentower 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def unsubscribe(email):
    return render_template('unsubscribe.html',email=email)
letters.py 文件源码 项目:margy 作者: opentower 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def admin():
    return render_template('admin.html')
letters.py 文件源码 项目:margy 作者: opentower 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def tail():
    if request.method == 'POST':
        fi = request.form['file']
        if os.path.isfile(fi):
            n = int(request.form['n'])
            le = io.open(fi, 'r', encoding='utf-8')
            taildata = le.read()[-n:]
            le.close()
        else:
            taildata = "No such file."
        return render_template('tail.html',taildata=taildata)
letters.py 文件源码 项目:margy 作者: opentower 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def wladd():
    if request.method == 'POST':
        addr = request.form['addr'].lstrip().rstrip()
        f = io.open('static/whitelist.txt', 'a', encoding="utf-8")
        f.write(addr.decode('utf-8') + u'\r\n')
        f.close()
        return render_template('wladd.html')
letters.py 文件源码 项目:margy 作者: opentower 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def unsub():
    if request.method == 'POST':
        addr = request.form['addr'].lstrip().rstrip()
        f = io.open('unsubscribers.txt', 'a', encoding="utf-8")
        f.write(addr.decode('utf-8') + u'\r\n')
        f.close()
        f = io.open('static/whitelist.txt', 'r', encoding="utf-8")
        lines = f.readlines()
        f.close()
        f = io.open('static/whitelist.txt', 'w', encoding="utf-8")
        for line in lines:
            if addr not in line:
                f.write(line.decode('utf-8'))
        f.close()
        return render_template('unsubscribed.html',addr=addr)


问题


面经


文章

微信
公众号

扫码关注公众号