###前提・実現したいこと
Python用のマイクロWeb開発フレームワークFlaskを用いてwebページを作る方法を学んでいます。
以下の記事を参考に進めているのですが、指示通りにコードを書いても、ブラウザで正しく表示されないため、どのように改善すれば良いかアドバイスいただきたいです。
基本的なJinja2の使い方の項目の「辞書型の変数を渡す」を参考にしています。
参考記事
HTMLをブラウザで開くとこのように表示され、
記事の指示にあった
http://localhost:5000/index
にアクセスすると
Internal Server Error The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
というエラー文が表示されるので、
Pythonの
my_dic['name'] = ryo2851 my_dic['univ'] = 'hogehoge University'
が適用されたwebサイトが作れていない状況で困っています。
###該当のソースコード
Python
1# coding: utf-8 2from flask import Flask, render_template 3app = Flask(__name__) #インスタンス生成 4 5@app.route("/") #アリケーションルートにアクセスが合った場合 6def hello(): #hello関数が動作します。 7 return "Hello World!" #ブラウザ画面に"Hello World!"と出力されます。 8 9@app.route("/index") 10def index(): 11 my_dic = {} 12 my_dic['name'] = ryo2851 13 my_dic['univ'] = 'hogehoge University' 14 return render_template('index.html', message=my_dic) 15#ここがサーバーサイドからクライアントサイドへなにかを渡すときのポイントになります。 16 17if __name__ == "__main__": 18 # webサーバー立ち上げ 19 app.run()
HTML
1<!DOCTYPE html> 2<html lang="en"> 3 <head> 4 <meta charset="utf-8"> 5 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 6 <meta name="viewport" content="width=device-width, initial-scale=1"> 7 <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> 8 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> 9 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script> 10 </head> 11<body> 12 <div class="container"> 13 <div class="header"> 14 <h3 class="text-muted">Sample Page</h3> 15 {% if message %} 16 <p>name: {{message.name}}</p> 17 <p>univ: {{message.univ}}</p> 18 {% endif %} 19 </div> 20 </div> 21 </body> 22 23</html>
###補足情報(言語/FW/ツール等のバージョンなど)
ターミナルでpythonのファイルは起動させています。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/11/26 01:33