All Blogs Go to Heaven
What I'm Using - Part II
Published: July 15, 2019, 5:27 p.m.
Edited: Aug. 12, 2019, 12:25 p.m.
Last week my wrist and elbow were hurting and I eventually bought a brace for my wrist and it immediately started helping. I went from sitting on the couch with my arm raised taking Ibuprofen to type with the brace on that very day. I was even feeling well enough to paddle a canoe all weekend while camping. I'm amazed at how well it worked and a bit embarrassed I didn't get a brace sooner.
In What I'm Using - Part I I went over mostly OS and general setup.
I am using Django. Python is the language I am most comfortable with so I had an option between Django and Flask for a framework (I'm sure there are others, but those are the big ones).
There are two fundamental reasons I wanted Django over Flask and one circumstantial one:
- Excellent admin functionality
- Very well documented
- I found a good course!
Let's do this in reverse order!
I found a good course!
I found a course on Udemy that covered HTML, CSS, and Javascript. I had never used CSS or JS and I hadn't really used HTML much. I am a firm believer that it is good to learn whatever is taught best and this course covered the things I wanted from beginning to end and used Django. If it happened to use Flask I might have used that.
This clearly not fundamental to Django vs. Flask, but the circumstance made Django more appealing.
Very well documented
Flask has good documentation, but I am in awe of the Django documentation. Third party tutorials and stackoverflow are great, but having good official documentation makes a big difference. There is a central resource that everyone should follow. Of course, there are some downsides here. Django needs more documentation because it has more rules. With Django I feel like I am forced into a certain architecture whereas Flask allows some more freedom. Removing some of that decision making can help get a project off the ground. Of course, without good documentation it does the exact opposite.
Excellent admin functionality
The built in Django admin is very simple to use and quite powerful. For most basic usage you can use it with no customization. Once the model has been defined, you get the admin for free! Since the admin is just a special Django app, it can be customized. On the easy side I added a group options for publishing one or many blog posts. If the application requires the admin page to be an integral part, just about everything, down to html/css/javascript can be overridden. It is really nice to have a quick and simple method to update a site and not need to design that tool while also creating another app.
So what are the down sides?
So far I've only noticed two.
- Lots of new syntax and infrastructure to learn
- Lots of boilerplate
Lots of new syntax and infrastructure to learn
There have already been some very simple actions that couldn't be easily implemented the way I expected. For example, posting only "published" blogs. I clearly don't want a blog to appear just because I have saved it. The quickest way to do that is using logic in the template tags. That is what I did first. I don't like template tags. Maybe I'm being unreasonably opinionated, but I'd like to have my server side logic be Python as often as possible. Using template tags is pretty easy but it seems like an unnecessary addition. Why should I have anything beyond formatting happening in the HTML? I eventually read up a bit on querysets and Class Based Views and I now have that logic in the view (my model describes WHAT I have, the view decides WHICH of those should be displayed and which template to use, and the template decides HOW to display... right?). If I were writing this in Flask I wouldn't have any of the built in CBVs (although the same pattern is supported in Flask) and I would have just written the middle layer how I want.
Lots of boilerplate
There are sooooooo many files and most of them have very little in them. If I don't want any special options for the admin page, I still need
admin.py
for each app to register each model for that app. I promised I would profess my love for PyCharm and I probably won't fully do that now, but I'll start. PyCharm handles all of the boilerplate well. Sure, any IDE will do a decent job, but PyCharm (pro) has Flask and Django built-in. I rely on PyCharm to clean up my HTML and Python and find my way through the options. Documentation is great, but sometimes just browsing the actual data stored in an object is easier to comprehend.I don't provide a way of commenting or contacting me and I'm sure there aren't millions of people reading this, so I don't expect any hate-mail about you preferred IDE, but I'm sure it's great too! I just really like PyCharm having used Atom, VSCode, and PyCharm for Python (and a little Eclipse for Java and XCode for C++). The community version is great and the pro version has been very helpful for web work.
Next time, I'll try to finish up with the last bits about this site and then start moving on to some new things I'm working on.