2016-03-24 12 views
2

フラスコを使用してサーバーを起動しようとするとこのエラーが発生します。マイテンプレートファイルは、私はエラーを取得するテンプレートフォルダ(flaskr /テンプレート)テンプレートを使用しているときフラスコエラーが発生しました

import sqlite3 
from flask import Flask, request, session, g, redirect, url_for, \ 
    abort, render_template, flash 

app = Flask(__name__) 

@app.route('/templates/') 
@app.route('/templates/<name>') 
def hello(name=None): 
    return render_template('index.html', name=name) 

if __name__ == '__main__': 
    app.run() 

である:

Not Found

The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

+1

それは言いますURLは間違っています...あなたは '/ hello /'に行きましたか?または '/'に?または、他の何か?あなたはいつもあなたがエラーを得るために何をしたのかを記述するべきです。 – Carpetsmoker

+0

残念ながら更新されたコード。私はちょうどコードを実行し、私はサーバーのURLに行くときにエラーが発生します – Mus

+0

"サーバーのURL"とはどういう意味ですか?ブラウザのアドレスバーに入力したURLはどれですか? – Carpetsmoker

答えて

1

それがこの(ディレクトリ構造)のようにする必要があり、アプリケーションの構造

と間違って何か

テスト/

----hello.py

がなければなりません----テンプレート/

-------- index.html

-------- hello.html

hello.py

from flask import Flask, render_template 
app = Flask(__name__) 

@app.route('/') 
@app.route('/index') 
def index(): 
    return render_template('index.html') 

@app.route('/templates/') 
@app.route('/templates/<name>') 
def hello(name=None): 
    return render_template('home.html', name=name) 

if __name__ == '__main__': 
    app.run(debug=True) 

index.htmlを

<h1> Index page</h1> 

hello.html

<h1> Home </h1> 
<h1> Hello {{name}}</h1> 
0

あなたは、テンプレートのルートを提供する必要はありません、フラスコを自動的にいることを処理します。

import sqlite3 
from flask import Flask, request, session, g, redirect, url_for, \ 
    abort, render_template, flash 

app = Flask(__name__) 

@app.route('/') 
@app.route('/<name>') 
def hello(name=None): 
    return render_template('index.html', name=name) 

if __name__ == '__main__': 
    app.run() 
+0

こんにちは、 私はまだエラーが発生します。私は自分のhtmlファイルを調べましたが、エラーはありません( "HI") – Mus

+0

ファイルを保存してから、サーバーを再実行する必要があります。その後、HTTP 'に行く:// localhostを:5000 /'や 'ます。http:// localhostを:5000/hello' - あなたのテンプレートでは、' こんにちはようこそ{{名前}}を持っている必要があります' –

+0

内部サーバーエラーがまだ発生 – Mus

関連する問題