My Little Python: Django is Magic

“Something tells me everything is not going to be fine.” — Twilight Sparkle, Season 3 Episode 13

Danin Sudjono
PDB+R
5 min readFeb 25, 2019

--

A little bit about myself

Before we start, let me begin with a small disclaimer. The first article written in the PDB+R series, titled “And so it begins…” was indeed written and proofread together, but the paragraph structure was mostly my work. I intended to make a fully English post as an introductory to our project, but refrained from doing so as I felt an Indonesian article would be more appropriate. That’s not going to stop me from writing my own personal stories in English, although I’ll probably be constantly switching between English and Indonesian, so excuse me if it does end up looking like South Jakartan lingo.

Anyway, perkenalkan, nama saya Fardhan Dhiadribratha Sudjono. Biasanya dipanggil Danin. Jika ingin tahu mengapa, langsung tanya aja, ceritanya nggak panjang. Saya berperan sebagai Hacker dalam kelompok PPL D3 atau PDB+R. Not much else to say here.

What are we doing?

Seperti yang dijelaskan di artikel pertama, kelompok kami menerima permintaan dari Pusilkom untuk memperbarui sistem sidang CSUI. Proyek ini kami beri nama SI SIDANG NG, yang kepanjangannya Sistem Informasi SIDANG New Generation.

I made this in like 5 minutes

Yang membuat proyek ini menarik dan sulit adalah fungsionalitas yang diharapkan, yaitu dapat mengakomodir tiga tipe pengguna yang berbeda (Dosen, Mahasiswa, dan Sekretariat). Algoritma kode tidak susah, hanya saja Product Backlog Item (PBI) yang harus diselesaikan berjumlah 50!

So what have I been doing?

I’m gonna skip talking about the Scrum framework, Test-Driven Development, and other theoretical filler content for now and cut to what I’ve been doing for the past week. Thanks to the structure of our project and the list of things that need to be done, work division in our group is a bit sketchy, to say the least. Our Hustler is the one with the DevOps job, all the hackers will be coding both front-end and back-end, our Hipster also codes full stack. Some of the Hackers in the group including myself helped with the creation of the web mock-up and logo design, which probably should be the Hipster’s job. Let’s just say everyone is doing everything.

Untuk sprint pertama, saya mendapat tugas untuk CRUD (Create, Read, Update, Delete) data jadwal sidang, front-end dan back-end. Pada waktu penulisan artikel ini, saya baru melakukan satu commit yang telah di push ke branch user story, yaitu membuat unit test untuk halaman front-end.

I had one job

Untuk progress halaman html jadwal sidang sendiri bisa dikatakan lumayan selesai. Saya berencana untuk mengubah dan menambahkan beberapa hal sebelum commit dan push yang terbaru, salah satunya adalah navbar dan header yang telah dirancang oleh Hipster kami.

What does the title of this article mean?

Ah, yes. Django is magic. Here I want to share a bit of my experience with setting up my local Python Virtual Environment. Some parts will not have screenshots because I actually forgot to document myself stressing out on this for an hour, and I would rather not recreate every step of that situation so bear with my explanations.

So as how one would start a project, once our wonderful Hustler finished the initial Django project, I went to clone our repository and make an app for myself. To try out the python manage.py runserver command, I had to make a virtual environment for our dependencies, using python -m venv env. Now usually you would turn on the environment and pip install here, but here’s what happened to me:

Ain’t that a shocker

So the solution to this one was actually pretty simple. I tried running where pip and this is what happened.

Well hello there

My good old friend Perl. So basically Perl also has a pip (perl installation program, of course) and because I had Dwimperl installed, the pip command was referring to the wrong pip. So I removed Dwimperl from my system variables.

But turns out it didn’t end there. Here’s what happened next:

I had to search StackOverflow for this one, and apparently it had something to do with my pip installation being incorrect. The solution to this one was actually just to upgrade my pip. Once upgraded, I ran the pip install command again, and all seem to go well… until the Django package. Funny thing is, I have an old version of Django installed within my Anaconda library, and while the newer version is installed in the virtual environment, it refused to use the newer Django. This also happened with a few other dependencies, like coverage, gunicorn, etc. I tried uninstalling said dependencies with pip uninstall, but that didn’t work (screenshot missing).

This caused me to do a lot of trial and error in remaking the virtual environment. Also caused me to delete a whole bunch of stuff. I think I spent a good hour around here, browsing StackOverflow and ranting to my teammates.

My recycle bin

Turns out once I deleted all the old versions from the Anaconda directory and made a new environment, the dependencies fixed itself with the pip install command, and the runserver command was finally working. How did that happen? I have absolutely no idea. So yeah, Django is magic.

God bless

So what did I learn?

I think that about does it for this first article. I hope nobody experiences what I did, but thanks to that, I now understand a bit more about the Python Virtual Environment, how its dependencies work, and how to workaround bad versions of dependency installations. With this out of the way, I hope I can focus on finishing and refactoring my front-end job before the deadline, and I hope PDB+R willmake this thing a big success! Until next time.

--

--