In this lab, you will learn about reading, adding, editing and deleting info from a realtime database! As well as the structure of the database.
Before we start, make sure to go to open the folder from the previous lab, and continue to work there.
-
Setting up Realtime Database in
Firebase
:- Go to your console and choose your project.
- Go to Realtime Database and create a database.
- Go to rules and change false to true.
- Make sure to copy the database's link.
-
Setting up Realtime Database in
app.py
:- In the config dictionary add databaseURL as a key and the link you copied as the value.
- Intialize the 'db' using the firebase object.
-
Add in
signup.html
3 inputs:full_name
username
bio
- It should take a maximum of 280 letters.
-
When the user signs up:
- Create a dictionary called user that contains the inputs' name as keys and and the inputs as values.
- Add the user to the
database
through the childUsers
adding him through his uid (retrieve it through login_session).
-
Create a form in
add_tweet.html
to add a tweet to the database:- The form should contain:
Title
.Text
- It should take a maximum of 280 letters.- Don't forget to add action and method
- The form should contain:
-
When the user submits a tweet:
- Create a dictionary called
tweet
that contains the inputs' name as keys and the inputs as values. - In the dictionary add a key named
uid
and the value as the uid of the user that wrote the tweet. - Add the tweet using the child
Tweets
to thedatabase
with a random key (the push method).
- Create a dictionary called
-
Create an html page called tweets.html & a route called
/all_tweets
:- in this html page display all the tweets that were written:
- Go to the child
Tweets
and use get().val()
- Go to the child
- in this html page display all the tweets that were written:
If you have extra time, continue to the Bonus Problems below.
If not, make sure your code is pushed.
-
Add a Tweet Timestamp attribute! It should take the real time and date and save it in Tweet.
-
Add a like button:
- It should add 1 like to a specific
tweet
, everytime a like button has been clicked using the database.
- It should add 1 like to a specific