Databases Group Project (Namtrak)
Install flask by running:
pip install flask
Install pip if you haven't since it's pretty useful anyway.
Go into the dabi_app directory, run:
python2 run.py
Go to http://localhost:5000/ (or http://127.0.0.1:5000/) in your web browser and you'll get the index page. Alternatively, add a page e.g. http://localhost:5000/search_results.html to go directly to it.
Remember your browser has a cache, so any changes you make while the server is up and running might not be immediately visible. For best results, refresh using CTRL-<F5> so the cache is ignored.
The directories are organized as such:
-
the root directory contains this file, the
requirements.txtfile which outlines the packages required to runflask, as well as the required versions, and thenew_schema.sqlfile, which was used to initialize our database with the correct tables and some sample data. Within the root directory we also have the following directories:-
reportdirectory: Contains TEX file and resulting PDF file for the report submitted earlier in the semester. -
dabi_appcontains our code. In it, we have:-
The
database.dbfile contains our SQLite database. We are currently in the process of shifting away from SQLite and towards MySQL. -
The
__init__.pyfile defines the location of files containing code necessary forflaskto properly display pages and respond to requests. -
The
create_seats_free.pyfile is used to generate thecreate_seats_free.sqlfile, which in turn was used to populate thefree_seatstable of our database. We elected to automate this process due to the sheer number of entries thatfree_seatswould require. For reference, the python script is only 253 bytes in size, while the SQL file generated is over 700 kilobytes. Even thenew_schema.sqlfile, used to initialize the database, is less than a tenth of that size, at 51.2 kilobytes. -
The
appdirectory contains the following:-
__init__.pyis required forflaskto run properly. -
models.pycontains various utility functions called on to interface with the database as well as to resolve variables used to render templates. -
views.pyis where the functions used to render templates are defined. Defining a new page is done by first creating a template for it in thetemplatesdirectory, and adding a route inviews.pyto have the desired page requested render the template we created. For example, accessing thecheck_schedulepage on the website will run thecheck_schedulefunction inviews.py, which runs theget_all_stationsfunction frommodels.pyand assigns the return value to a variable, which is then passed into therender_templatefunction to render the template defined, which will be looked for inside thetemplatesdirectory. Instances ofall_stationsin the specified template will be replaced with the value passed into thereturn_templatefunction. -
The
staticdirectory contains the CSS and JavaScript files used to control how the pages look. -
The
templatesdirectory contains all the templates used. Most of them extendlayout.html, since that is the page which contains everything we'd like to include in the majority of pages on our website, such as script and style declarations, as well as the navigation bar at the top of the pages. The other template should be quite self-explanatory, as they consist of mostly unspectacular HTML. The text in between curly braces is used by the template rendering engine to determine how the templates are to be rendered. For example, inconfirmation.html, we have the text "Thank you! Ticket number for Passender {{ passenger_id }} is {{ticket_num}}". On callingrender_template, we must also pass in the variables we would like to use forpassenger_idandticket_num. These are obtained by calling functions frommodels.py. The template rendering engine will then replace {{ passenger_id }} and {{ticket_num}} with the values provided when returning a complete HTML page to be displayed in a browser.
-
-
-