Désolé, j'ai recherché dans le stackoverflow et googlé, mais aucune information utile n'a été trouvée. J'ai une application de flacon, Python version 2.6 version flacon 0,9dupliqué url_prefix dans Flask en utilisant blueprint
sa hiérarchie d'application est comme
application/
__init__.py
app.py
hello/
__init__.py
view.py
templates/
hello.html
les deux fichiers initialisation .py sont vides
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>
Il fonctionne très bien quand je rentre localhost:8080/hello
, mais se révèle erreur si je clique sur le lien en html. J'ai trouvé sa valeur d'URL est href="/hello/hello/"
(Devrait-il être /hello/
droit?). Je sais hello.get_index est mappé à /hello/
, mais je ne sais pas que le premier hello/
vient. Tout indice est apprécié.
J'ai commencé une application utilisant votre code (mais avec 'app.run()' au lieu de 'WSGIServer (. ..). run() '), et le lien est bien. Supposons le problème en quelque sorte lié à WSGI – HighCat
Merci beaucoup pour votre test! Je vais regarder dans WSGI pour voir ce qui a causé ce problème. –