2
对不起,我在里面搜索了stackoverflow和google搜索,但没有找到有用的信息。 我有一个烧瓶应用, Python版本2.6 烧瓶版本0.9使用蓝图在Flask中复制url_prefix
其应用层次是像
application/
__init__.py
app.py
hello/
__init__.py
view.py
templates/
hello.html
两个文件初始化的.py是空
app.py
-----------------------
from flask import Flask
from flup.server.fcgi import WSGIServer
from hello.view import hello
app = Flask(__name__)
app.debug = True
app.register_blueprint(hello, url_prefix='/hello')
if __name__ == '__main__':
WSGIServer(app, bindAddress='/tmp/app.sock').run()
view.py
-----------------------
import os
from flask import Blueprint, render_template, abort
from jinja2 import TemplateNotFound
hello = Blueprint('hello', __name__, template_folder='templates')
@hello.route('/')
def get_index():
try:
return render_template('hello.html')
except TemplateNotFound:
abort(404)
hello.html
-----------------------
<!DOCTYPE html>
<html>
<head>
{% block head %}
<meta charset="utf-8">
{% endblock %}
</head>
<body>
<div>
{% block body %}
<h1><a href="{{ url_for('hello.get_index') }}">Click Me</a></h1>
{% endblock %}
</div>
</body>
</html>
它工作正常,当我输入localhost:8080/hello
,但是如果我点击html链接就会发现错误。我发现它的url值是href="/hello/hello/"
(应该是/hello/
对不对?)。 我知道hello.get_index映射到/hello/
,但不知道第一个hello/
来自何处。任何暗示是赞赏。
我已经开始使用你的代码的应用程序(但有''app.run的(),而不是'WSGIServer(。 ..)。run()'),并且链接很好。假设这个问题与WSGI – HighCat 2012-07-26 07:58:50
相关,非常感谢您的测试!我将研究WSGI以查看造成此问题的原因。 – 2012-07-26 12:39:00