Python | Flask Url_For MissingSchema:无效Url错误

2024-07-04 05:51:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我在试图从用户所在的当前页面中删除html时遇到问题。。基本上,用户正在创建一个训练列表来创建一个训练例程,用户正在从一个选择字段中进行选择,每次他们单击“添加”按钮时,它都会填充一个他们迄今为止选择的训练列表。然后,我将从该列表中获取文本,并将其与数据库中的内容进行匹配 请求中出现了我的问题。get(url\u for('createARoutine'))

requests.exceptions.MissingSchema:无效URL'/createaroutine':未提供架构。也许你的意思是http:///createaroutine?

使用直接url测试时”http://127.0.0.1:5000/createaroutine“我的错误更改为werkzeug.routing.BuildError:无法生成端点的url”http://127.0.0.1:5000/createaroutine'. 你是说“createARoutine”吗?

@app.route("/createaroutine", methods=["GET", "POST"])
def createARoutine():
    """
    present form to creatine new routine, each time user clicks to 
    add an exercise, show the exercise to the side"""
    form = CreateRoutineForm()
    query = Exercises.query.all()
    choices = [(c.id, c.name) for c in query]
    form.exercises.choices = choices

    # collect all exercises and add to routine, 
    # also add routine to users favorites
  
    if request.method == 'POST':
        this_html = requests.get(url_for('createARoutine'))     <----ERROR
        soup = BeautifulSoup(this_html, 'html.parser')
        p = soup.find_all("li", {"id": "exerciseChoices"})
        print(p)
        return redirect(url_for('showWorkoutRoutines'))
    return render_template("createRoutine.html", form=form)

`


Tags: to用户formaddhttpurl列表for
1条回答
网友
1楼 · 发布于 2024-07-04 05:51:01

这将不起作用,因为requests需要一个完全限定的url,包括您运行的服务器

另一方面,我很难理解你为什么要这么做!您正在使用get调用自己的站点,而不是从您所在的位置访问数据。这是个糟糕的主意。您拥有精确函数中所需的所有数据。如果您需要html,它在模板中。你永远不应该做你在这里做的事

相关问题 更多 >

    热门问题