Templates and Static Files in Puput

Templates and Static Files in Puput

One of the ways Puput really confuses me is its not adding a visible app into the project folder. Normally, when you run “django-admin manage.py startapp app_name_here”, you see a folder for your app appear. Not with Puput. I haven’t figured it out completely yet but I think the app is somehow integrated into the Puput package in the Python folder. Or, maybe the app isn’t really in the package folder, but it simply acts as the app itself and uses your database to generate the web site. I don’t know.

I need to override Puput’s templates and static files, and this Stack Overflow post shows that you can do that with the template files. But for the life of me I couldn’t use the same principle or find another way to override the static files. (UPDATE: figured it out, same principle does apply, I mistook PROJECT_DIR for BASE_DIR.)

It led me to another question though. What’s the difference between STATICFILES_DIR, STATIC_ROOT, and STATIC_URL? This post answers it in part. But I still can’t override the static files. I tried reverse-engineering the Puput package but I’m not good enough to figure it out yet.

Well. I guess I’ll edit the source static files directly for now. Not a good idea, I know. But I can’t just sit around stalled all the ruddy week.

Notes on Installing Puput on Wagtail on Django

Notes on Installing Puput on Wagtail on Django

This is a brief one, I hope.

I wanted to save time so I learnt Django. Then I wanted to save more time building a CMS and a blog so I learnt Wagtail. Then I wanted to save even more time so I learnt Puput. The problem was, as I went from Django to Wagtail to Puput, the documentation got thinner and thinner and thinner. And more and more and more abstract. Not ideal for beginners, at all.

Wagtail “Post date” Problem

I followed the Wagtail introductory tutorial strictly, but when I used “date = models.DateField(“Post date”)” like in the tutorial, I kept getting: “django.core.exceptions.ValidationError: [“‘Post date’ value has an invalid date format. It must be in YYYY-MM-DD format.”]”.

After googling for a full day, I got fed up and visited the Wagtail channel on IRC Freenode where someone said to run “manage.py migrate blog zero”, remove all files in the migrations folder except for __init__.py and then run makemigrations and migrate again to start from scratch. That meant all my test posts were gone but it fixed the problem.

Nobody knew exactly what went wrong. I suspect it’s because when we follow tutorials and test things out in different ways we might create conflicts in the database. I don’t know. Just guessing.

Puput Installation Problem

The bigger problem arrived when I tried to integrate Puput into my Wagtail project. The documentation does tell you how to do it, except that it throws up a few errors irresolvable by beginners. Since I didn’t have a full blown blog I had to integrate, I was comfortable dumping my test Wagtail blog entirely and building the Puput one from scratch.

The Puput setup documentation says you have to do different things depending on whether you’re installing Puput on top of Wagtail or on top of Django. I’ve found neither to work when strictly followed. Instead, what worked was when I followed the setup instructions for integrating Puput into a Django project minus the part where you add PUPUT_APPS into INSTALLED_APPS.

Once I left it out, I could migrate without error code 1 and other errors showing up. Then I could build the blog up from scratch.

Other Issues

I solved a handful of other problems by following the code. If the tutorial said to do something but it didn’t work, I would go into the Puput package, weasel out the module I’m supposed to be referencing, find the appropriate code in it, and try to understand what exactly it does. This was harder than I thought, since half of it didn’t make sense to me. The other half did though, thankfully.

Wagtail works slightly differently from Django, and Puput is almost entirely different structurally. They’re not difficult to understand. It just takes a lot of time, googling, and asking around, and thank goodness for IRC, amirite?

I thought using open source packages would save me time, and perhaps it will in the long run. I do really like Puput and Wagtail and Django. But it can be really hard on beginners, especially when some of us have to work to pay the rent and we’re stealing literally ten bare minutes off the end of the day to learn this stuff with bleary eyes and tired minds.

Clear documentation and tutorials are so important. I hope I get some free time and energy to write up clearer ones for Puput soon.

Projects so far

Projects so far

Documenting what I’ve built so far. I don’t have the $$ to host these yet, so, I’ll post pics for now.

The Nomurica Constant International Film Fest

I built this web app to counter the winner-takes-all effect in popular culture. American culture saturates every last bit of our environment, and I felt this buried great works from the rest of the world six feet under. So, I took the IMDB database, banned all films from America and most of the West, and let my algorithm randomly pick ten films from around the world, scrape YouTube for their trailers, and post them on a webpage.

I built this in Flask, and the code is shoddy because I made this before I learnt more about MVC. I know better now, and I’ll rebuild it in Django when I have the time. This experience also let me understand how much faster it is to use PostgreSQL over SQLite3.

I think, even considering its many faults right now, it looks like significantly effective proof-of-concept that it is more than possible to remedy the winner-takes-all effect, and consequently, cultural hegemony.

nomurica constant international film fest page 1


I built this app as an exercise in both language and code. Essentially, I constructed a way to randomly concatenate several lists of strings so that they always turn out grammatically correct. The background slowly segues from one colour to another, and the text also changes every so often.

It’s also built in Flask.


A social media site

I’ve also built, in Flask, a social media site where people log in and out and share events. It’s not time to show it publicly yet but, working on user accounts gave me an idea of how insecure a site can be when built by a beginner without any knowledge of SQL sanitisation.

It was this site that made me finally pick up Django, which I hoped would solve my security issues for me. While learning Django, I found out about Django-allauth, and the way it uses ORMs, which was heartening.

Last bit

I’ve learnt a lot. I can make web apps/websites in Flask, and I’m beginning to feel my way into Django.

I read that a lot of compsci grads can’t even code fizzbuzz. Does this mean I’m good enough for a job? I don’t know. I still don’t have the confidence to apply. I wish someone would tell me. It’s easy to say, hey, you can just ask. But more often than not, people tell me, yeah, ask me any time, and then they are way too busy to reply to me every time I ask. And online forums can be untowardly harsh to beginners, which is hardly good for anyone with anxiety issues.

I also wish I’d had teachers who guided me. But, I suppose, I go it alone as usual, and hope for the best. It’s really slow. But I guess, I’m getting somewhere?

I’ve started on JavaScript too. ūüôā

Deployment: The Next Big Batch of Knowledge After Flask

Deployment: The Next Big Batch of Knowledge After Flask

I’ve begun thinking about how to deploy my app. It would have been easy as a one-pager, but my app has a PostgreSQL database, and it is a social networking site, which means I should prepare for lots and lots of users (assuming people pick it up at all).

Rooting around in this direction turned up this helpful video that tells you about different ways to host your app. It also turned up the idea of “workers”. Heroku and DigitalOcean use workers. What are these? I don’t know yet. Of course there are definitions, as usual. But definitions try to be one-stop shops and catch-all solutions, and in catering to everyone, they cater to no one at all. Ok, I exaggerate. They cater to some. Dictionaries do a pretty decent job although they don’t tell you about nuances, connotations, and other baggage that comes with words.

While researching workers and deployment, I realised that I have to look at sharding, and possibly logical sharding in particular. Also connection pools, database caching, clustering, cloud formation, load balancing, docker/virtualisation, and batching writes to the database. In short, it seems, I have to learn some devops.

We meet again, prong of epistemology. To go from Flask to deployment means learning a whole critical bunch of things.

The bad thing is, I don’t know how much I should know about devops, so I’m groping around in the dark, and groping around for all kinds of different things. To mix two idioms, I’m a drowning man in the dark clutching at straws. The good thing, I suppose, is that I think I know the primary question here: how many requests can a worker handle? It’s a surprisingly hard question to answer, and I have to answer it so I know if the cheapest plan on DigitalOcean is suitable for a starting social networking web app. I’ll root around some more.

Deployment also made me think about marketing, which led me to this video, which reminded me that I have to cite open source code, which means I have to review all my code and try to remember where each part of it came from if I didn’t write it myself.

At the same time, I’ve learnt and exercised enough Flask to know that I should pick up Django and rebuild the entire app in it, and that I should also learn JavaScript, because a lot of interactions, like socketio, depends on it.

Does the prong of epistemology become larger and larger as knowledge increments? At this point, I should be working in a team with proper front end and back end developers and designers, right? But with only basic Python, Flask, and SQL under my belt, what team roughing it out in the savage wilderness of live business operations would want me? “Not good enough”, that old refrain.

But, hey, the only way forward is forward.

What is Model-View-Controller (MVC)

What is Model-View-Controller (MVC)

I was totally confused over how to use flask-security, and researching that made me super confused about sessions vs. cookies vs. tokens, and researching that brought me to the topic of the model-view-controller (MVC). Long story short, I found a pretty good video that introduces the paradigm:

After watching it, I realised I could reduce my code by maybe 90% if I abstracted away huge repetitive bunches of it. I knew this in the back of my mind before but was too caught up learning the basic basics to think about it clearly. Anyway, after watching a few more videos, I think this is one of the better introductions. It provides a brief enough history that segues smoothly into contemporary practice.

I’m still completely baffled with flask-security and slightly more clear about sessions-cookies-tokens. RTFM not working, especially for flask-security.

Quick Word on Jobs

Quick Word on Jobs

I picked code up in part to get a better paying job than anything on offer in the arts. Now I have Python, Flask, and SQL with me. However, after going through job sites for a few days, I’ve discovered that most jobs are for front end developers with HTML5, CSS, and Javascript.

There is a lot of demand for Javascript using AngularJS, React, NodeJS, etc. So, the fastest way to get a job is to pick up front end web dev/design skills.

If you stick with Python and want to do some back end work, you’ll need Django, and NoSQL, typically MongoDB. Not Flask. Exceedingly few¬†hiring companies use¬†Flask.

Ruby on Rails appears quite a bit too. Also a lot of demand for UI/UX. But that floats into a more distant skill set.