小编Exc*_*ity的帖子

Flask url_for函数中的Jinja变量

我尝试了多种不同的东西,但无法将URL显示为/ item,就像我想要的那样.我知道其他一切都正常运行,因为如果我只是用字符串替换{{item}},它就可以正常工作.我在这里错过了什么吗?

以下是问题所在的代码部分:

<div class="person_images_group">
    {% for item in names %}
        <div class="personlist">
            <a href={{ url_for('name', name = {{item}} ) }}>
                <img id={{ item }} src="" alt={{ item }} width="40" height="40">
            </a>
        </div>
        <script>
            document.getElementById("{{ item }}").src = getName("{{ item }}");
        </script>
    {% endfor %}
<div>
Run Code Online (Sandbox Code Playgroud)

谢谢

convention variables jinja2 url-for flask

10
推荐指数
1
解决办法
1万
查看次数

如何使用Blueprint在Flask中正确声明子域?

我一直在关注这篇文章中提供的方法:https: //stackoverflow.com/questions/12167729/flask-subdomains-with-blueprint-getting404

这是我的相关代码:

__init__.py

from flask import Flask, render_template

app = Flask(__name__, static_url_path="", static_folder="static"
import myApp.views
Run Code Online (Sandbox Code Playgroud)

views.py

from flask import Flask, render_template, request, Blueprint
from myApp import app

app.config['SERVER_NAME'] = 'myapp.com'
app.url_map.default_subdomain = "www"

@app.route("/")
def index():
    return "This is index page."

test = Blueprint('test', 'test', subdomain='test')

@test.route("/")
def testindex():
    return "This is test index page."

app.register_blueprint(test)

if __name__ == "__main__":
    app.run()
Run Code Online (Sandbox Code Playgroud)

使用这种方法,我可以让子域'测试'和'www'工作,但现在我无法通过IP地址访问我的网站.

任何指导正确的方向将不胜感激!

python subdomain flask

5
推荐指数
0
解决办法
646
查看次数

标签 统计

flask ×2

convention ×1

jinja2 ×1

python ×1

subdomain ×1

url-for ×1

variables ×1