1
- # Flask-WebApp-with-PostgreSQL-DB
1
+ # flask-webapp-postgresql-db
2
+
2
3
Artists Booking Venues powered by Python (Flask) and PostgreSQL Database
3
4
4
5
## Development Setup
6
+
5
7
1 . ** Download the project starter code locally**
6
- ```
7
- git clone https://github.com/John0Isaac/Flask-WebApp-with-PostgreSQL-DB.git
8
- cd Flask-WebApp-with-PostgreSQL-DB
9
- ```
10
8
11
- 2 . ** Before and After editing your code, Use the commands below:**
9
+ ``` bash
10
+ git clone https://github.com/john0isaac/flask-webapp-postgresql-db.git
11
+ cd flask-webapp-postgresql-db
12
+ ```
13
+
14
+ 2.** Before and After editing your code, Use the commands below:**
12
15
13
16
before editing anything pull new changes from GitHub.
14
- ```
17
+
18
+ ``` bash
15
19
git pull
16
20
```
21
+
17
22
Once you are done editing, you can push the local repository to your Github account using the following commands.
18
- ```
23
+
24
+ ``` bash
19
25
git add .
20
26
git commit -m " your comment message"
21
27
git push
22
28
```
23
29
24
- 3 . ** Initialize and activate a virtualenv using:**
25
- ```
30
+ 3.** Initialize and activate a virtualenv using:**
31
+
32
+ ``` bash
26
33
python -m virtualenv venv
27
34
source venv/bin/activate
28
35
```
36
+
29
37
> ** Note** - In Windows, the ` venv ` does not have a ` bin ` directory. Therefore, you'd use the analogous command shown below:
30
- ```
38
+
39
+ ``` bash
31
40
source venv/Scripts/activate
32
41
deactivate
33
42
```
34
43
35
- 4 . ** Install the dependencies:**
36
- ```
44
+ 4.** Install the dependencies:**
45
+
46
+ ``` bash
37
47
pip install -r requirements.txt
38
48
```
39
49
40
- 5 . ** Run the development server:**
41
- ```
50
+ 5.** Run the development server:**
51
+
52
+ ``` bash
42
53
export FLASK_APP=app.py
43
54
export FLASK_ENV=development
44
55
export FLASK_DEBUG=true
45
56
flask run --reload
46
57
```
47
58
48
- 6 . ** Verify on the Browser** <br >
59
+ 6.** Verify on the Browser**
60
+
49
61
Navigate to project homepage [ http://127.0.0.1:5000/ ] ( http://127.0.0.1:5000/ ) or [ http://localhost:5000 ] ( http://localhost:5000 )
50
62
63
+ ## Adding Routes
64
+
65
+ - Create the html, css, js in the specified folder using the same folder structure.
66
+ - Create a new route in the [ app.py] ( ./app.py ) file with the name you want using only dashes to separate words.
51
67
52
- # Adding Routes
53
- ## To add a new page
54
- * Create the html, css, js in the specified folder using the same folder structure.
55
- * Create a new route in the [ app.py] ( ./app.py ) file with the name you want using only dashes to seperate words.
56
68
``` PYTHON
57
69
@app.route (' NEW-ROUTE' )
58
70
```
59
- * Define your serving function using a unique name not used before in the whole application.
71
+
72
+ - Define your serving function using a unique name not used before in the whole application.
73
+
60
74
``` PYTHON
61
75
def NEW_UNIQUE_NAME ():
62
76
```
63
- * Return your html file path using render_template.
77
+
78
+ - Return your html file path using render_template.
79
+
64
80
``` PYTHON
65
81
return render_template(' FOLDER_PATH/FILE_PATH.html' )
66
82
```
67
- * Your newely created route should look like this.
83
+
84
+ - Your newly created route should look like this.
85
+
68
86
``` PYTHON
69
87
@app.route (' NEW-ROUTE' )
70
88
def NEW_UNIQUE_NAME ():
@@ -75,19 +93,20 @@ def NEW_UNIQUE_NAME():
75
93
76
94
1 . Open the Google Cloud Shell and execute the following command:
77
95
78
- ```
79
- git clone https://github.com/John0Isaac/Flask-WebApp-with-PostgreSQL-DB .git
80
- cd Flask-WebApp-with-PostgreSQL-DB
81
- ```
96
+ ``` shell
97
+ git clone https://github.com/john0isaac/flask-webapp-postgresql-db .git
98
+ cd flask-webapp-postgresql-db
99
+ ```
82
100
83
- 2 . Create the env_variables.yaml file that contains your secret environment variables.
101
+ 2.Create the env_variables.yaml file that contains your secret environment variables.
84
102
85
- ```
86
- nano env_variables.yaml
87
- ```
103
+ ``` shell
104
+ nano env_variables.yaml
105
+ ```
88
106
89
- 3 . Add your Google Cloud SQL database connection details
90
- ```
107
+ 3.Add your Google Cloud SQL database connection details
108
+
109
+ ``` shell
91
110
env_variables:
92
111
DB_USER_NAME: ' secret'
93
112
DB_PASSWORD: ' secret'
@@ -99,14 +118,16 @@ env_variables:
99
118
DEPLOYMENT_LOCATION: ' gcp'
100
119
```
101
120
102
- 4 . save and exit the file CTRL+x followed by y followed by Enter.
103
- 5 . Deploy the web application.
104
- ```
105
- gcloud app deploy app.yaml
106
- ```
121
+ 4.save and exit the file CTRL+x followed by y followed by Enter.
122
+
123
+ 5.Deploy the web application.
107
124
125
+ ``` shell
126
+ gcloud app deploy app.yaml
127
+ ```
108
128
109
129
## Deploying After Deleting Everything from Google Cloud
130
+
110
131
1 . Create a Cloud SQL instance using the following parameters:
111
132
- Specify instance name and password.
112
133
- Select production instead of production plus.
@@ -118,6 +139,7 @@ gcloud app deploy app.yaml
118
139
- Create a database and call it fyyur.
119
140
- Create a user and call it john.
120
141
- Grant All privileges to user john.
142
+
121
143
2 . Import Data dump.
122
144
3 . Pull the code to the Cloud Shell.
123
145
4 . Create environment variables .yaml file.
0 commit comments