重新加载页面时确认重新提交问题。我希望它能将其重定向到主页

问题描述 投票:0回答:1

一旦我们重新加载页面,就会出现一个弹出窗口,其中包含确认重新提交问题,而不是我想要主页和 我在下面有反馈,应该做出响应,一旦我单击拇指向上,它应该可见,它被选中,如果我将反馈更改为拇指向下,那么拇指向下应该在单击时可见,而拇指向上在按下时不应该可见,反之亦然。

应用程序.py

@app.route("/",methods=['get', 'post'])
def index():
 form = userinput()
 if request.method == 'POST':
   connect = apiurl
   resp = requests.post(connect)
   url = resp.json()['url']
   message = resp.json()['text']
   return render_template(home.html, title = 'index', form=form, url=url, message=message)
return render_template(index.html, form=form)

表格.py

class UserInput(FlaskForm):
    text = TextAreaField('Enter your Question ', validators=[DataRequired()])
    submit = SubmitField('Request for the Answer')
    feedback = StringField('Feedback')

index.html

{% extends "layout.html" %}
{% block content %}
<!--    <h1>Home Page</h1>-->
<!--    <span>Request Method - {{ request_method }}</span>-->
{% endblock content %}

home.html

{% extends "layout.html" %}
{% block content %}
        <ul class = "label-for-list"> Files:
            <li class="list"><a href="{{ url }}">{{ url }}</a></li>
        </ul>
        <div class ="second">
            <label for="exampleFormControlTextarea1" class="form-label">Answer: </label>
            <textarea class="form-control" id="exampleFormControlTextarea1" rows="12">{{ message }}</textarea>
        </div>
        <div class="feedback-button">
            {{ form.feedback.label(class="form-label") }}
            <input type="button" value="👍" class="emoticon" title="thumbs-up" onclick="console.log('Positive')" onmousedown="mousedown()" onmouseup="mouseup()">
            <input type="button" value="👎" class="emoticon" title="thumbs-down" onclick="console.log('Negative')">
        </div>
        <script>
            function mousedown(input){
                input.style.color = "blue";
            }
        </script>

{% endblock content %}

布局.html

<div class="container">
        <div class="content-section">
        <form method="POST" action="/">
            {{ form.hidden_tag() }}
            <fieldset class="form-group">
                <div class="form-group">
                    {{ form.text.label(class="form-control-label") }}
                    {{ form.text(class="form-control form-control-lg",rows="5") }}
                </div>
            </fieldset>
            <div class="form-group d-grid gap-2">
                {{ form.submit(class="btn btn-outline-info") }}
            </div>
            {% block content %}{% endblock %}
        </form>
        </div>
    </div>

api.py

from flask import Flask, request, jsonify
from flask_cors import CORS
from wonderwords import RandomSentence
import random

app = Flask(__name__)
CORS(app)


@app.route('/', methods=['GET', 'POST'])
def func():
    print(request.method)
    if(request.method == 'GET'):
        response = "This is just GET request and API is up and running"
        return jsonify({'response': response})

    elif(request.method == 'POST'):
        data = request.data.decode('utf-8')
        url = f"https:\\SourceDir\\file{random.randint(0,10)}.pdf"
        s = RandomSentence()
        # d = {"text":data.strip('\"'),'URL':url}
        d = {"text": s.sentence(), "URL": url}
        return d


if __name__ == '__main__':
    # app.run(debug=True)
    app.run(host="0.0.0.0", port=8000)
python html flask
1个回答
0
投票

我假设您想要一种在人们单击您的反馈按钮后重定向人们的方法,您只需使用

index
函数修改您的
redirect
函数即可。我假设您有一个
home
函数,喜欢您的
index

from flask import Flask, render_template, request, redirect, url_for

@app.route("/", methods=['GET', 'POST'])
def index():
    form = UserInput()
    if request.method == 'POST':
        connect = apiurl
        resp = requests.post(connect)
        url = resp.json()['url']
        message = resp.json()['text']
        # Store the result in the session or pass it via a redirect
        return redirect(url_for('home', url=url, message=message))
    return render_template('index.html', form=form)

您还需要在

JS
中编写脚本,通过获取按钮的
id
来监听点击等事件。


© www.soinside.com 2019 - 2024. All rights reserved.