Skip to main content

Posts about programming (old posts, page 9)

Premature end to a Hundred Days of Code. Welcome to A Month of Emacs

Life is really kicking my butt right now.
And the 12th studies are not making it any easier.
So am temporarily giving up on A Hundred Days of Code, again.

Hopefully, I will have the time to give Python, in a month.
In the meanwhile, with the limited time I do have, I’d like to learn me some Emacs.
Will write about it everyday.

Hiatus!

Lost a friend to the virus last night.
And a shit-ton of personal issues have cropped up at the same time.

Need to go handle and process all of this.
Will be back, when I am back.

A Hundred Days of Code, Day 047

Follow my whole plodding, Flask journey here.
Crashed and burned even harder today.
Tried to retrace my steps and did all the exercises again.
I reached, once more, all the way upto the forms chapter and it just does not work. Now it won’t even display my login page.

Was it worth doing?
Oh yes.
I gained a much better understanding of how Flask works, of what is required where.
Will work once more at the login page tomorrow.


A Hundred Days of Code, Day 046

Follow my whole plodding flask journey here..

Am still stuck at where I was yesterday.
But made a tiny bit of progress.

Yesterday, it would not even submit the form.
And now I got it to do that.
How? I had forgotten to close the form tag.

Now while I see that it is posting perfectly in the terminal, I cannot get it to reply with a message saying that I indeed have logged in.

Will start watching the videos again tomorrow, to see if I have missed something.
One thing that I am doing different from the course, is that I am using the new style f-strings, while the course uses a slightly older style.
Could it be, that some flask module might not like it?
Will work at it tomorrow and write down, what I figure out.


A Hundred Days of Code, Day 045

Follow my whole plodding journey here.

Wrote a basic login form today.
Short story short, it shows up, but it does not respond like Miguel shows in the course. It justs sits there … staring back at me … like an obstinate goat.

Will go spelunking into what I could have done wrong, tomorrow.

Learnt about adding routes and creating views and making templates.
Thoroughly confused though.
While I am dumbly following instructions right now, what I don’t get, is what do I need to write first? It all seems very circular to me.
What comes first? The route, the form, the template, the chicken or the egg?

Hopefully, I will gain clarity as I progress.


A Hundred Days of Code, Day 044

Continuing the Flask course.

Learnt about seperation of concerns today.
To me that means that I should try to keep related things together and disparate stuff apart.
Case in point, we1 created a seperate file config.py to store the variables about the program in. And then to kind of secure it even more, instead of hardcoding the password in the file, it now looks for an environment variable, which I need to set before running the program.
Another example was when we created a seperate file to process input (for our logins) and then put all the login, password etc. fields in there. This feels good. Feels like I am learning best practices and good habits already.

The file I created to process login input, is called a form (as in fill in this form? guess so) and uses the WTForms package to do the heavy lifting.
And that was where I learnt my next bit. Not only is Flask, made of modular pieces, it also has an ecosystem of various other modules (called flask extensions) that give it extra functionality, oomph and power.2

And here’s where I called it a day.


  1. Who we? Why, Miguel the instructor and me, of course XD 

  2. WTForms is an example 

A Hundred Days of Code, Day 043

Continuing with the Flask course.

Today I learnt about how to loop, using Jinja loop blocks.
The syntax is slowly becoming clear to me.
Everything python related in enclosed is {% … %} blocks, except for variables which use their own {{ … }} syntax.

What I am still confused on is the relationship between the various files, I am writing. There is html and then there are templates and there are python files themselves. Hopefully that will get clearer in the days to come.
My naïve understanding, right now, is

  1. Some native python code is mainly for launching and running the app.
  2. The html templates pull data from …
  3. The flask python code I write (the routes file, as of now).

I also learnt how to extend templates. I created a base template that basically contains the header and the title, which will now be used by every new webpage I build. Right now, it’s just the home page.
I can see a footer or header or some such persistent element that needs to be on every page, that can be created once and then extended multiple times.

More, tomorrow …

P.S. Looking at that finished app, and knowing my extremely rudimentary Python skills, I feel like an apprentice mason, hammer and a chisel in hand, wondering, how in heck, am I going to carve David?


A Hundred Days of Code, Day 042

Second day with the Flask course.

Beginning to realise that Flask is not a monolithic thing, but consists of a lot of moving parts.
Looking forward to learning what they are as I progress along.

Today I learnt how to set my Flask variable, and create an environment, so that I can run Flask consistently without problems.

Miguel also teaches a simple, yet effective way to combat yak shaving.
You know, where all you want is one simple thing, but then that depends on that other thing, which reminds you that you need that third thing and the next thing you know, you’re at the zoo, shaving a yak, all so you can wax your car.
Just don’t do that other thing.
Focus on what you are doing.
If there is something you need, use a dummy. Mock something up.
This is a very real, meta lesson, that I’ll carry with me for the rest of my days.

So I learnt how to return a web page.
And that got tiring really quickly.
Which is when Miguel introduced me to templates.
And I realise why they are needed.
I created a basic template and also learnt about conditionals in the templating language, Jinja and then I called a stop to the day.
More to follow tomorrow.


A Hundred Days of Code, Day 041

Started to very slowly do the Mega Flask Tutorial.
This real world project-cum-tutorial, should let me learn more real-world-esque Python and expand beyond the tiny vocabulary, I have.

Setup my environment today and created a baby flask app.
Even that had something to teach me.
I could not quite wrap my head around decorators, the first time I read about them and this tiny app uses routes in the form of decorators.
Which meant, I had to go read about them and understand them first.

Routes are paths.
And decorators are something (a function/class) that take your existing code and enclose it, whilst giving it extra functionality.

In my case, my code just printed a line.
And the route decorators, in my case, took that code and assigned it to a web page of my choosing.
Right now the home page is assigned to that line.
And if I choose to, I could assign any other url to that same line.
This was hard, but fun.

Looking to do more of this slow steady work over the coming weeks.


A Hundred Days of Code, Day 040

Done with the Talk Python course.
And now to shift to low intensity Python learning while I ramp up studies for the 12th exams.
Will probably learn Flask with Miguel Grinberg.