Week 7 of the boot camp experience with Coding Dojo went well, although I feel like I did struggle a little bit this week. My time to dedicate to learning was impacted by some pretty big personal matters, and I've spent the last few days halfway across the country for them. Aside from the personal matters taking up a lot of time this week the content itself proved challenging. Regardless, I am feeling confident in my ability to understand and retain the information as I move forward onto the next course of the program.
<usual_enterance> If you're new here I'm creating this blog series as I go from coding newbie to working in web3. I'm creating this to reflect on the technical and non-technical growth and to leave it behind for others who might be interested in how they can follow a similar path. </usual_enterance>
Flask
This course started with understanding how to set up virtual environments and running a web server before moving into broadening the understanding of how the system works. As always, feel free to correct or challenge my understanding of these concepts and check out the repo for the assignments from this course here.
Routes
Routes tell the server what information the client is looking for and points to a specific set of instructions.
@app.route('/hello_world')
def hello():
return "hello_world"
Rendering Views
Using this framework, html files have to stored in a directory called "templates". We call the html files via what I've put below in the code block.
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
Static Files
This is content sent to the client that doesn't need modified, generated, or processed by the server such as stylesheets, images, and JS files. These files must be stored in a directory called "static". These are then called in the html file like this:
<!-- css style sheet -->
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='my_style.css') }}">
<!-- JS file -->
<script type="text/javascript" src="{{ url_for('static', filename='my_script.js') }}"></script>
<!-- image -->
<img src="{{ url_for('static', filename='my_img.png') }}">
POST Form Submission
Looking at the code snippet below that belongs in the server.py file, we specify the methods (POST) and accessing data (request.form). When a form this is connected to in the HTML file is submitted this will pull the data and send it to the database.
from flask import Flask, render_template, request, redirect
@app.route('/users', methods=['POST'])
def create_user():
print("Got Post Info")
print(request.form)
return redirect('/')
Redirecting
POST form submissions should always be a redirect and not render to avoid duplicating data.
@app.route('/users', methods=['POST'])
def create_user():
print("Got Post Info")
print(request.form)
name = request.form['name']
email = request.form['email']
return redirect("/show")
Session
Session is a form of persistent data storage, establishes a client by saving data for use in the future.
@app.route('/users', methods=['POST'])
def create_user():
print("Got Post Info")
session['username'] = request.form['name']
session['useremail'] = request.form['email']
return redirect('/show')
Hidden Input
These are form fields that are hidden from the user and used to transfer information between different pages.
<input type="hidden" name="action" value="register">
Projects
Bootcamp Flask Assignments
This "project" is really just the assignments from the Flask course of the bootcamp. This project was wrapped up this week and I may return to it later for some additional optional assignments.
The repo.
Personal Portfolio Website
My portfolio website saw some big changes this week with a fresh README that helped organize the content and share more relevant information. Additionally, I implemented Devicon to help with displaying the language familiarity. The content for this page is moving forward as well, with the majority of projects and experiences having been included in the files. This next week, I'll be looking to finish most of the content for the sections.
The repo.
Doors vs Wheels
The Doors vs Wheels project was born from the Tik Tok trend that centered on the debate of whether there are more doors or wheels in the world. This will be a simple web application that would allow the user to submit the data from their households and contribute to the global count. A TA from the boot camp has volunteered to collaborate on this so we will be working on this together and it will likely be completed by the end of the new week.
The repo.
What's Next?
I finished up the Flask course content, and moving into this new week I'll be tackling Flask + MySQL where we will be integrating previously learned materials from different courses. The projects are moving forward with comfortable speeds so I'm satisfied with
If you'd like to join the learning community I'm building on Discord for web3, you can find the link for that here. It's a space that I am trying to build for myself and others to share their growing knowledge of all things web3.
You can also find me here:
LinkedIn | GitHub | Twitter | My Website