当我的烧瓶网页处于“获取"状态时,方法,它无法连接到通常在"POST"中执行的任何静态文件.方法 [英] When my flask web page is in "GET" method, it couldn't connected to any static files it normally does in "POST" method

查看:86
本文介绍了当我的烧瓶网页处于“获取"状态时,方法,它无法连接到通常在"POST"中执行的任何静态文件.方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

===============解决方案已添加到以下=================

我有 python代码,可让用户在帖子页面上编辑其评论.

当用户单击下面的此按钮时:

<a href="{{ url_for('blog_posts.blog_info_update', blog_validated_id=post2.blog_post_id, blog_info_id=post2.blog_info_id) }}"><button class="btn btn-light btn-sm text-muted ">Edit</button></a>

他们将请求"GET"页.然后,当他们完成编辑并发布评论(或form2)时,他们将请求发布".另一个页面的版本:

@blog_posts.route('/<int:blog_validated_id>/<int:blog_info_id>/update', methods=['GET', 'POST'])
@login_required
def blog_info_update(blog_validated_id, blog_info_id):

    blog_view = BlogPost.query.get_or_404(blog_validated_id)
    blog_info_update = BlogInfo.query.get_or_404(blog_info_id


    form2 = BlogInfoForm()

    if form2.validate_on_submit():
        blog_info_update.text=form2.text.data
        db.session.commit()
        return redirect(url_for('blog_posts.blog_view', blog_validated_id=blog_validated_id, form2=form2)
                                

    elif request.method == 'GET':
        form2.text.data = blog_info_update.text


    return render_template('blog_view.html', blog_validated_id=blog_validated_id, form2=form2, 
                                blog_info_id=blog_info_update.blog_info_id)

但是,当我进入此获取"页面时,该页面的版本,我看到某些代码(我在静态文件中编写并连接到我的HTML文件的代码)未显示其功能.我认为此获取"功能存在问题模式干扰了我的静态文件(如下所示),如果您能帮助我解决此问题,我将不胜感激:

以下代码是我将HTML文件链接到的代码:

 {% extends "base.html" %}

{% block content %}   
<link rel="stylesheet" href="../static/css/blog_view.css">
    <script type="text/javascript" src="../static/javascript/blogview.js"></script>

{% endblock %}

显示我的问题的图像:

(如下@gelonida所建议,相对路径或/45/static/css/blog_view.css存在问题.相比之下,/static/css/base.css可以正常工作)

谢谢!

解决方案

当我从上面抽出一点@Prakhar Gupta的代码时,问题就解决了:

     <link rel="stylesheet" href="{{ url_for('static', filename='css/blog_view.css') }}">
    <script type="text/javascript" src="{{ url_for('static', filename='javascript/blogview.js') }}"></script>

静态文件中的其他图像必须按照我为上述href编写的相同方式编写,以免遇到@gelonida所说的相对URL问题.

P.s/我要感谢@gelonida和@Prakhar Gupta帮助我提出自己的解决方案:)

===============SOLUTION HAD BEEN ADDED BELOW==================

I have the python codes that let users edit their comments on a post page.

When the users click on this button below:

<a href="{{ url_for('blog_posts.blog_info_update', blog_validated_id=post2.blog_post_id, blog_info_id=post2.blog_info_id) }}"><button class="btn btn-light btn-sm text-muted ">Edit</button></a>

They will request a "GET" page. Then when they finished editing and post the comment (or form2), they will request a "POST" version of another page:

@blog_posts.route('/<int:blog_validated_id>/<int:blog_info_id>/update', methods=['GET', 'POST'])
@login_required
def blog_info_update(blog_validated_id, blog_info_id):

    blog_view = BlogPost.query.get_or_404(blog_validated_id)
    blog_info_update = BlogInfo.query.get_or_404(blog_info_id


    form2 = BlogInfoForm()

    if form2.validate_on_submit():
        blog_info_update.text=form2.text.data
        db.session.commit()
        return redirect(url_for('blog_posts.blog_view', blog_validated_id=blog_validated_id, form2=form2)
                                

    elif request.method == 'GET':
        form2.text.data = blog_info_update.text


    return render_template('blog_view.html', blog_validated_id=blog_validated_id, form2=form2, 
                                blog_info_id=blog_info_update.blog_info_id)

However, when I went to this "GET" version of the page, I see that some codes ( those that I wrote in the static files and connected to my HTML file ) are not showing their functions. I think there is a problem with this "GET" mode that is interfering with my static files (shown below) and I would greatly appreciate if you could help me fix this problem:

The codes below are the one I'm linking my HTML file with:

 {% extends "base.html" %}

{% block content %}   
<link rel="stylesheet" href="../static/css/blog_view.css">
    <script type="text/javascript" src="../static/javascript/blogview.js"></script>

{% endblock %}

An image that shows my problem:

(As @gelonida suggested below, there is a problem with the relative paths or /45/static/css/blog_view.css. In contrast, /static/css/base.css works fine)

Thank you!

解决方案

The problem was solved when I twitched a little bit of @Prakhar Gupta's code from above:

     <link rel="stylesheet" href="{{ url_for('static', filename='css/blog_view.css') }}">
    <script type="text/javascript" src="{{ url_for('static', filename='javascript/blogview.js') }}"></script>

Other images from the static file will have to be written in the same way I wrote for the href like above in order to not meet relative URLs issue as @gelonida said.

P.s/ I want to thanks @gelonida and @Prakhar Gupta for helping me to come up with my own solution :)

这篇关于当我的烧瓶网页处于“获取"状态时,方法,它无法连接到通常在"POST"中执行的任何静态文件.方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆