【发布时间】:2022-09-27 20:42:23
【问题描述】:
文档的 id 需要作为可选参数在 url 中。
- 例如它当前的 https://..../view-document
- 我需要它是 https://..../view-document/______
id 是用户在 neo4j 数据库中单击的任何文档,必须放在 url 的末尾
要更改的代码部分是 路线.py
@app.route(\'/view-document\', methods=[\'GET\', \'POST\'])
def view_document():
document_link = active_document_link
document_filepath = os.path.join(\'../static/sample_documents\', document_link)
document = get_document_from_document_link(document_link)
user_name = get_active_user_name()**
index.js
function openDocument(documentFormat, documentLink) {
fetch(\"/open-document\", {
method: \"POST\",
body: JSON.stringify({ documentFormat: documentFormat, documentLink: documentLink })
}).then((_res) => {
window.location.href = \"/view-document\";
});
}
我很确定这些是我需要更改才能工作的部分 iv设法解决的是
路线.py
@app.route(\'/view-document/<name>\', methods=[\'GET\', \'POST\'])
def view_document():
name = document[\'name\'] <!--to access the neo4j database-->
document_link = active_document_link <!--i was told to get the document link from the url instead of from \"active_document_link\" -->
document_filepath = os.path.join(\'../static/sample_documents\', document_link)
document = get_document_from_document_link(document_link)
user_name = get_active_user_name()
index.js
function openDocument(documentFormat, documentLink) {
fetch(\"/open-document\", {
method: \"POST\",
body: JSON.stringify({ documentFormat: documentFormat, documentLink: documentLink })
}).then((_res) => {
window.location.href = \"/view-document/<name>\";
});
}
标签: python flask url-routing dynamic-url