Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何仅使用python代码(非js)通过flask中的按钮将新日期值传递给URL_Python_Html_Flask_Url - Fatal编程技术网

如何仅使用python代码(非js)通过flask中的按钮将新日期值传递给URL

如何仅使用python代码(非js)通过flask中的按钮将新日期值传递给URL,python,html,flask,url,Python,Html,Flask,Url,我正在研究flask中的应用程序,该程序为员工显示rota时间表,以供参考。我设法为一名选定的员工显示了本月的轮换表。看起来是这样的: 当我输入间隔值作为当前日期时,它显示当前月份 其URL为: 当我直接在URL中更改日期,即2020-10-14时,它将正确显示所选驾驶员的2020年10月rota时间表。我想编程一个按钮“下个月”和“上个月”,让人们改变使用按钮的日期。我写了一个函数来实现它,但我不知道如何传递值来构建正确的URL 这是我在flask_应用程序中的代码: @app.route

我正在研究flask中的应用程序,该程序为员工显示rota时间表,以供参考。我设法为一名选定的员工显示了本月的轮换表。看起来是这样的:

当我输入间隔值作为当前日期时,它显示当前月份

其URL为:

当我直接在URL中更改日期,即2020-10-14时,它将正确显示所选驾驶员的2020年10月rota时间表。我想编程一个按钮“下个月”和“上个月”,让人们改变使用按钮的日期。我写了一个函数来实现它,但我不知道如何传递值来构建正确的URL

这是我在flask_应用程序中的代码:

@app.route("/individual", methods=['GET', 'POST'])
def individual():
    rotamonth = date.today()
    return render_template('individual.html', title='Individual', drivers=drivers, rotamonth=rotamonth)


@app.route("/individual/printrota/<rotamonth>", methods=['GET', 'POST'])
def printrota(rotamonth):
    pickname = request.args.get("pickname")
    dispmonth = datetime.today().strftime('%B %Y')
    for driver in drivers:
        if driver.first == pickname:
            chosen_driver = driver
            forward = chosen_driver.add_one_month()


            return render_template('printrota.html', chosen_driver=chosen_driver,mon_thu_times=mon_thu_times,fri_times=fri_times, sat_times=sat_times, sun_times=sun_times, dispmonth=dispmonth, rotamonth=rotamonth, forward=forward)

@app.route("/backmonth")
def backmonth():
    pass


@app.route("/individual/printrota/<rotamonth>", methods=['GET', 'POST'])
def forward(rotamonth):

    return render_template('printrota.html')
@app.route(“/individual”,方法=['GET','POST']))
def individual():
rotamonth=日期。今天()
返回呈现模板('individual.html',title='individual',drivers=drivers,rotamonth=rotamonth)
@app.route(“/individual/printrota/”,方法=['GET','POST'])
def printrota(rotamonth):
pickname=request.args.get(“pickname”)
dispmonth=datetime.today().strftime(“%B%Y”)
对于驱动程序中的驱动程序:
如果driver.first==pickname:
选择的驱动程序=驱动程序
前进=选择的驱动程序。添加一个月()
返回渲染模板('printrota.html',selected_driver=selected_driver,mon_thu_times=mon_thu__times,fri_times=fri_times,sat_times=sat_times,sun_times=sun_times,dispmount=dispmount,rotamonth=rotamonth,forward=forward)
@应用程序路线(“/后月”)
def backmonth():
通过
@app.route(“/individual/printrota/”,方法=['GET','POST'])
def前进(rotamonth):
返回render_模板('printrota.html')
这是我的模板代码:

individual.html:

{% extends "layout.html" %}
{% block content %}
 <div class="subpage">
    <h1>INDIVIDUAL ROTA</h1>
     <form action={{url_for('printrota',rotamonth=rotamonth)}}>
         <label>Choose a name:</label>
         <select name="pickname" id="pickname">
         {%for driver in drivers%}
           <option value={{driver.first}}>{{driver.first}}</option>
         {%endfor%}
         </select>
         <input type="submit" value="Pick a name">
     </form>
 </div>
{% endblock content %}
{%extends“layout.html”%}
{%block content%}
个人轮换
选择一个名称:
{驱动程序%中的驱动程序为%1}
{{driver.first}
{%endfor%}
{%endblock内容%}
printrota.html:

{% extends "layout.html" %}
{% block content %}
<div class="subpage">
<h1>{{chosen_driver.first}}'s rota for {{dispmonth}}</h1>
    <form>
    <button class="move_rota" type="submit">Previous month</button>
    </form>
    <form action={{url_for('printrota', rotamonth=forward, chosen_driver=chosen_driver)}}>
    <button class="move_rota" type="submit">Next month</button>
    </form>
<table class="table table-bordered table-dark">
    <tr>
        <th>DATE</th>
        <th>DAY</th>
        <th>DUTY</th>
        <th>TIME SPAN</th>
    </tr>
{%for item in chosen_driver.clnd(rotamonth, period='M')%}
    <tr>
        <td>{{item.start_time.date()}}</td>
        <td>{{item.start_time.strftime('%A')}}</td>
        <td>{{item.label}}</td>
        {% if item.start_time.weekday() in range(0,4)%}
            <td>{{ mon_thu_times[(chosen_driver.clnd(item.start_time.date()).label)] }}</td>
            {% elif item.start_time.weekday() == 4%}
            <td>{{ fri_times[(chosen_driver.clnd(item.start_time.date()).label)] }}</td>
            {% elif item.start_time.weekday() == 5 %}
            <td>{{ sat_times[(chosen_driver.clnd(item.start_time.date()).label)] }}</td>
            {% elif item.start_time.weekday() == 6 %}
            <td>{{ sun_times[(chosen_driver.clnd(item.start_time.date()).label)] }}</td>
        {% endif %}
    </tr>
{%endfor%}
</table>
</div>
{% endblock content %}
{%extends“layout.html”%}
{%block content%}
{{{selected_driver.first}}的{{{disp month}的rota
上月
下个月
日期
白天
责任
时间跨度
{所选驱动程序.clnd(rotamonth,period='M')%中的项的%
{{item.start_time.date()}}
{{item.start_time.strftime(“%A”)}
{{item.label}
{%if item.start_time.weekday()的范围为(0,4)%}
{{mon_thu_times[(选择的_driver.clnd(item.start_time.date()).label)]}
{%elif item.start_time.weekday()==4%}
{{fri_times[(选择的_driver.clnd(item.start_time.date()).label)]}
{%elif item.start_time.weekday()==5%}
{{sat_times[(选择_driver.clnd(item.start_time.date()).label)]}
{%elif item.start_time.weekday()==6%}
{{sun_times[(选择_driver.clnd(item.start_time.date()).label)]}
{%endif%}
{%endfor%}
{%endblock内容%}
我尝试先对“下个月”按钮进行编程,然后分别将其应用于另一个按钮。当我按下按钮时,URL如下所示:

?

并返回错误:

TypeError:view函数未返回有效响应。函数返回None或结束时没有返回语句

这意味着日期传递正确,但另一个参数(即拾取的员工)没有出现,并且无法生成页面,因为它缺少显示正确计划所需的参数“pickname”。我不知道如何将其传递到此URL

我试图在文档和类似的问题中寻求帮助,但这里似乎没有任何东西对我有用。救命