I have two routes, the first one collects two variables that will be shown in the second route (template) by clicking submit. But if I write the URL from the second one (/viewtrips) on the browser then the two variables are not shown because they were never selected and stored in the global variables. So I want to prevent this. Is there any command e.g. a request?
The code for the first route '''
@route('/', method=['GET', 'POST'])
def homepage():
if request.method == 'POST':
planet = request.forms.get('destination') # destination will be selected from a
#dropdown menu and the click will be store and sent here
dateTime = request.forms.get('date')
global formDateTime
global formPlanet
formDateTime = dateTime
formPlanet = planet
redirect('/viewtrips') #send us to the next page
else:
return template('templateHome')
'''
For the second one:
'''
@route('/viewtrips', method=['GET', 'POST'])
def viewTrips():
global formPlanet
global formDateTime
flighttime = flightTime(formPlanet) #giving the variable to a function in another py file
gifPlanet = gifplanet(formPlanet) # returns a gif
planet = formPlanet
datetime = formDateTime
basePrice = planetPrice(formPlanet)
if request.method == 'POST':
seat =request.forms.get('seating')
food = request.forms.get('food')
global formSeat
global formFood
formSeat = seat # values are stored in variables to insert them later in the database
formFood = food
redirect('/information')
return template('templateBooking', flighttime = flighttime, datetime = datetime, gifPlanet = gifPlanet, basePrice = basePrice, destination = planet)
'''
HTML for the first template:
'''
<form method="POST">
<label id="to">To:</label>
<select id="destination" name="destination" required>
<option value="" disabled selected>Choose aDestination</option>
<option value="Mercury">Mercury</option>
<option value="Venus">Venus</option>
<option value="Mars">Mars</option>
<option value="Jupiter">Jupiter</option>
<option value="Saturn">Saturn</option>
<option value="Uranus">Uranus</option>
<option value="Neptune">Neptune</option>
</select>
<label for="date" style="margin-left:15px">Date:</label>
<input type="date" id="date" name="date" placeholder="Date" required>
<input type="submit" value="submit">
</form>
'''
For the second one:
'''
<form method="POST">
<p id="chooseseating">Choose your seating:</p>
<input type="radio" id="seating" name="seating" value="Economy" required>
<label for="seating1"> Economy Class ( +20M$ )</label><br>
<input type="radio" id="seating" name="seating" value="Business" required>
<label for="seating2"> Business Class ( +55M$ )</label><br>
<input type="radio" id="seating" name="seating" value="First" required>
<label for="seating3"> First Class ( +70M$ )</label>
<p id="chooseseating">Include Food service?</p>
<input type="radio" id="seating" name="food" value="Yes"required>
<label for="food">Yes ( +2M$ )</label><br>
<input type="radio" id="seating" name="food" value="No"required>
<label for="food">No</label><br>
<input type="submit" value="submit">
</form>
</div>
<div class="box22">
<form method="GET">
<img id="solarsystem" src="{{gifPlanet}}" align="right">
</form>
</div>
'''
'''
import bottle
from bottle import run, template, route, request, redirect, static_file
from requests import session
from PlanetDestination import flightTime, gifplanet, price, planetPrice
from database import dataInput,extractInfo, delete, editInfo, updateInfo, emailextraction
from Passangers import init_db
import PlanetsGif
import json
import bottle_session
app = bottle.app()
plugin = bottle_session.SessionPlugin(cookie_lifetime=600)
app.install(plugin)
#init_db()
#PlanetsGif.PlanetName_GIF()
#PlanetsGif.SolarSystem_GIF()
# global variables for future purposes
@route('/', method=['GET', 'POST'])
def homepage():
if request.method == 'POST':
planet = request.forms.get('destination')
dateTime = request.forms.get('date')
session['destination'] = planet
session['date'] = dateTime
redirect('/viewtrips') #send us to the next page
else:
return template('templateHome')
'''