{"id":1707,"date":"2018-03-28T21:12:00","date_gmt":"2018-03-28T12:12:00","guid":{"rendered":"http:\/\/www.python.ambitious-engineer.com\/?p=1707"},"modified":"2018-11-04T22:38:12","modified_gmt":"2018-11-04T13:38:12","slug":"flask%e3%81%a7%e4%bd%9c%e3%82%8b%e7%b0%a1%e6%98%93%e5%88%86%e6%9e%90%e3%83%84%e3%83%bc%e3%83%ab7-flash%e3%83%a1%e3%83%83%e3%82%bb%e3%83%bc%e3%82%b8","status":"publish","type":"post","link":"https:\/\/www.python.ambitious-engineer.com\/archives\/1707","title":{"rendered":"Flask\u3067\u4f5c\u308b\u7c21\u6613\u5206\u6790\u30c4\u30fc\u30eb7 flash\u30e1\u30c3\u30bb\u30fc\u30b8"},"content":{"rendered":"<p>\u524d\u56de\u3067\u3001\u30c4\u30fc\u30eb\u3068\u3057\u3066\u4f7f\u3046\u305f\u3081\u306e\u6700\u4f4e\u9650\u306e\u6a5f\u80fd\u306e\u5b9f\u88c5\u306f\u7d42\u308f\u308a\u307e\u3057\u305f\u3002\u3053\u3053\u304b\u3089\u306f\u88dc\u8db3\u6a5f\u80fd\u306e\u8ffd\u52a0\u3068\u3057\u3066flush\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u8ffd\u52a0\u3092\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>flask\u306eflash\u30e1\u30c3\u30bb\u30fc\u30b8<\/h2>\n<p>flash\u30e1\u30c3\u30bb\u30fc\u30b8\u3068\u306f\u3001\u51e6\u7406\u304c\u7d42\u308f\u3063\u305f\u308a\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u969b\u306b\u305d\u306e\u65e8\u3092\u901a\u77e5\u3059\u308b\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u3053\u3068\u3067\u3059\u3002flask\u306b\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067flash\u30e1\u30c3\u30bb\u30fc\u30b8\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u305d\u308c\u3092\u4f7f\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u4fee\u6b63<\/h3>\n<p>\u307e\u305a\u306f\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306bflash\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u633f\u5165\u3059\u308b\u90e8\u5206\u3092\u8ffd\u52a0\u3057\u307e\u3057\u3087\u3046\u3002base.html\u306econtainer\u90e8\u5206\u3092\u4ee5\u4e0b\u306e\u901a\u308a\u4fee\u6b63\u3057\u3066\u304f\u3060\u3055\u3044\u3002\uff08block body\u306e\u524d\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002\uff09<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;div class=&quot;container&quot;&gt;\r\n    {% for message in get_flashed_messages() %}\r\n    &lt;div class=&quot;alert alert-success&quot;&gt;{{ message }}&lt;\/div&gt;\r\n    {% endfor %}\r\n    {% block body %}{% endblock %}\r\n&lt;\/div&gt;\r\n<\/pre>\n<p>get_flashed_messages\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u306b\u3088\u308a\u3001\u30bb\u30c3\u30b7\u30e7\u30f3\u306b\u683c\u7d0d\u3055\u308c\u305f\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>\u5404\u51e6\u7406\u306e\u4fee\u6b63<\/h3>\n<p>run.py\u3067\u3001flask\u306eflash\u6a5f\u80fd\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nfrom flask import Flask, request, g, redirect, url_for, render_template, flash\r\n<\/pre>\n<p>\u307e\u305f\u3001\u66f4\u65b0\u7cfb\u306e\u51e6\u7406\u7d42\u4e86\u5f8c\u306bflash\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8ffd\u52a0\u3059\u308b\u3088\u3046\u306b\u4fee\u6b63\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n# run.py\r\n@app.route('\/analysis', methods=['POST'])\r\ndef analysis():\r\n    &quot;&quot;&quot; \u5206\u6790\u5b9f\u884c\u51e6\u7406 &quot;&quot;&quot;\r\n\r\n    title = request.form['title']\r\n    data = request.form['data']\r\n    img = models.create_scatter(data)\r\n\r\n    con = get_db()\r\n\r\n    pk = models.insert(con, title, data, img)\r\n    flash('\u767b\u9332\u51e6\u7406\u304c\u5b8c\u4e86\u3057\u307e\u3057\u305f\u3002')    # \u2190\u3053\u3053\u3092\u8ffd\u8a18\r\n    return redirect(url_for('view', pk=pk))\r\n\r\n\r\n@app.route('\/delete\/&lt;pk&gt;', methods=['POST'])\r\ndef delete(pk):\r\n    &quot;&quot;&quot; \u7d50\u679c\u524a\u9664\u51e6\u7406 &quot;&quot;&quot;\r\n    con = get_db()\r\n    models.delete(con, pk)\r\n    flash('\u524a\u9664\u51e6\u7406\u304c\u5b8c\u4e86\u3057\u307e\u3057\u305f\u3002')    # \u2190\u3053\u3053\u3092\u8ffd\u8a18\r\n    return redirect(url_for('index'))\r\n<\/pre>\n<h2>\u52d5\u4f5c\u78ba\u8a8d<\/h2>\n<p>\u767b\u9332\u3001\u524a\u9664\u51e6\u7406\u3092\u884c\u3063\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n<a href=\"http:\/\/www.python.ambitious-engineer.com\/wp-content\/uploads\/2018\/03\/flask_flash.png\"><img loading=\"lazy\" src=\"http:\/\/www.python.ambitious-engineer.com\/wp-content\/uploads\/2018\/03\/flask_flash.png\" alt=\"\" width=\"1304\" height=\"772\" class=\"alignnone size-full wp-image-1708\" srcset=\"https:\/\/www.python.ambitious-engineer.com\/wp-content\/uploads\/2018\/03\/flask_flash.png 1304w, https:\/\/www.python.ambitious-engineer.com\/wp-content\/uploads\/2018\/03\/flask_flash-300x178.png 300w, https:\/\/www.python.ambitious-engineer.com\/wp-content\/uploads\/2018\/03\/flask_flash-768x455.png 768w, https:\/\/www.python.ambitious-engineer.com\/wp-content\/uploads\/2018\/03\/flask_flash-1024x606.png 1024w\" sizes=\"(max-width: 1304px) 100vw, 1304px\" \/><\/a><\/p>\n<p>\u767b\u9332\u3001\u524a\u9664\u51e6\u7406\u5f8c\u306b\u753b\u9762\u4e0a\u90e8\u306b\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u305f\u3089\u6210\u529f\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u56de\u3067\u3001\u30c4\u30fc\u30eb\u3068\u3057\u3066\u4f7f\u3046\u305f\u3081\u306e\u6700\u4f4e\u9650\u306e\u6a5f\u80fd\u306e\u5b9f\u88c5\u306f\u7d42\u308f\u308a\u307e\u3057\u305f\u3002\u3053\u3053\u304b\u3089\u306f\u88dc\u8db3\u6a5f\u80fd\u306e\u8ffd\u52a0\u3068\u3057\u3066flush\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u8ffd\u52a0\u3092\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002 flask\u306eflash\u30e1\u30c3\u30bb\u30fc\u30b8 flash\u30e1\u30c3\u30bb\u30fc\u30b8\u3068\u306f\u3001\u51e6\u7406\u304c\u7d42\u308f\u3063\u305f\u308a\u30a8\u30e9...<\/p>\n","protected":false},"author":1,"featured_media":1720,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[153,3,9],"tags":[171,170],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/1707"}],"collection":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/comments?post=1707"}],"version-history":[{"count":5,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/1707\/revisions"}],"predecessor-version":[{"id":1973,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/1707\/revisions\/1973"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media\/1720"}],"wp:attachment":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media?parent=1707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/categories?post=1707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/tags?post=1707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}