首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flask,Jinja2 -缺少位置参数,但我提供了多个

Flask,Jinja2 -缺少位置参数,但我提供了多个
EN

Stack Overflow用户
提问于 2020-12-02 09:15:30
回答 1查看 52关注 0票数 1

我已经被这个错误困扰了很长一段时间。我是Jinja2和Flask的新手,但我已经尝试过修改我的for循环和在我的main.py中编辑东西,但都无济于事。这是我到目前为止所得到的。

首先,我的main.py

代码语言:javascript
复制
# Data Science Notes Route
@app.route('/data-science/<content>')
def note(content):   
    return render_template('notes.html', content=content)

接下来,我的模板中导致错误的部分。

代码语言:javascript
复制
{% for link in category_files %}

    <h2 class="file-title"><a href="{{ url_for('note', content=get_note_content(link)) }}"
            class="file-link">{{ note_dict[link].title }}</a></h2>

    <!-- Display a description of the file -->
    <p class="file-description">{{ note_dict[link].description }}</p>

    <!-- Display the topics covered -->
    <p class="file-topics">Topics covered: {{ note_dict[link].topics }}</p>

    <!-- Display an image -->
    <img src="{{ note_dict[link].image }}" alt="">

    {% endfor %}```

The issue is that very first part with the `a` tag.  According to the error message, I am missing the **content** argument.  But it looks to me like I'm not!  Here's the error output, as well as the `dump()` output. 

[![Image of Error][1]][1]

Any aid would be greatly appreciated!  Thanks!


  [1]: https://i.stack.imgur.com/iyqN0.png
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-02 09:37:42

您的URL路由中未包含filepath

代码语言:javascript
复制
@app.route('/<note_title>/<filepath>', methods=['GET'])
def note(note_title, filepath):
    ....

如果你想把filepath作为url参数,那么:

代码语言:javascript
复制
from flask import request
@app.route('/<note_title>', methods=['GET'])
def note(note_title):
    filepath = request.args.get('filepath')
    ....
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65100864

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档