我想要获取参数格式def:a()到def:b()的值并返回到html文件。如何在python烧瓶的不同路径中将def的值传递给def?
@app.route('/a',methods=['GET','POST'])
def a():
if request.method == 'POST':
text_a = request.form.get('text')
return render_template('index.html')
AND
@app.route('/b',methods=['GET','POST'])
def b():
if request.method == 'POST':
return render_template('index.html',text = text_a )
return render_template('index.html' )
PS>路径/ a中的我想输入文本并提交,然后将/ a的值获取到/ b
HTML文件
<form method="POST" action= "/a" >
<input type="text" name="text">
<input class="btn btn-primary" type="submit" value="submit">
</form>
{{text}}
谢谢您的帮助。
答案 0 :(得分:0)
Sub SetPrintArea()
index.html
Sub FitMyTextPlease()
Application.ScreenUpdating = False
ThisWorkbook.Sheets("Print version").PageSetup.CenterHeader = "&""Times New Roman,Bold""&12 " & Range("Data!V28").Text & Chr(13) & Chr(13) & " " & "&""Times New Roman,Normal""&12 " & Range("Data!V30").Text
'ThisWorkbook.Sheets("Print version").PageSetup.CenterHeader = Range("Data!V28").Text
ThisWorkbook.Sheets("Print version").Select
With ActiveWorkbook.ActiveSheet
With .Cells.Rows
.WrapText = True
.VerticalAlignment = xlCenter
.EntireRow.AutoFit
End With '.Cells.Rows
.Columns.EntireColumn.AutoFit
End With 'sheet
Application.ScreenUpdating = True
End Sub
Sub HideMyEmptyRows()
Dim myRange As Range
Dim cell As Range
Application.ScreenUpdating = False
Set myRange = ThisWorkbook.Sheets("Print version").Range("Print_Area")
For Each cell In myRange
myRange.Interior.ColorIndex = 0
If cell.HasFormula = True And cell.value = "" And cell.EntireRow.Hidden = False Then Rows(cell.Row).EntireRow.Hidden = True
Next
Application.ScreenUpdating = True
End Sub
Sub SetPrintArea()
Dim ws As Worksheet
Dim lastrow As Long
Set ws = ThisWorkbook.Sheets("Print version")
' find the last row with formatting, to be included in print range
lastrow = ws.UsedRange.SpecialCells(xlCellTypeLastCell).Row
ws.PageSetup.PrintArea = ws.Range("A1:C" & lastrow).Address
End Sub
Sub Printed_Pages_Count()
Range("A1").value = (ActiveSheet.HPageBreaks.Count + 1) * (ActiveSheet.VPageBreaks.Count + 1)
End Sub
Sub FitGroupsToPage()
Dim rStart As Range, rEnd As Range, TestCell As Range
Dim lastrow As Long, PgSize As Integer
Dim n As Integer
PgSize = 91 ' Assumes 91 rows per page
Set rStart = Range("C1")
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
Do
Set TestCell = rStart.Offset(PgSize, 0)
If Len(TestCell) = 0 Or Len(TestCell.Offset(-1, 0)) = 0 Then
Set rEnd = TestCell.End(xlUp)
Else
Set rEnd = TestCell.End(xlUp).End(xlUp)
End If
ActiveWindow.SelectedSheets.HPageBreaks.Add Before:=rEnd.Offset(1, 0)
Set rStart = rEnd.Offset(1, 0)
n = n + 1
If n > 1000 Then Exit Sub ' Escapes from an infinite loop if code fails
Loop Until rStart.Row > lastrow - 50
End Sub
Sub FitMyHeadings()
Call FitMyTextPlease
Call HideMyEmptyRows
Call SetPrintArea
Call FitGroupsToPage
Call Printed_Pages_Count
End Sub
好读 https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world
答案 1 :(得分:0)
您可以使用Flask sessions存储从一个请求到下一个请求的信息。
@app.route('/a',methods=['GET','POST'])
def a():
if request.method == 'POST':
session['text_a'] = request.form.get('text')
return render_template('index.html')
@app.route('/b',methods=['GET','POST'])
def b():
if request.method == 'POST':
return render_template('index.html',text=session['text_a'] )
return render_template('index.html' )