Saturday, March 19, 2016

Testing The Django Framework - Documenting The Process

I have decided to go through the installation of the Django framework on my Windows machine. I am doing the same thing simultaneously on my Linux machine, but am currently only documenting the process on Windows. There are many reasons for this, mainly because doing anything with Python on a Windows machine is categorically more difficult than doing just about anything on a Linux machine. In other words, if you are running Linux, you don't need a tutorial on installing and working with the Django framework. (More or less).

Basically, I just opened up a terminal/console and typed in:

$ pip install Django==1.9.4

Then, for good measure, I typed the following, to make sure everything is working:

$ python -c "import django; print(django.get_version())"

This is all easy to find information on the Django project website. I'm just following the basic tutorials. The real reason I am doing this is not just to show how to install Django. It has more to do with the fact that I want to look at the way Django sets up projects.

In essence, I want to look at the directory structure and basic files of a "skinned down", "bare-bones" Django project. I plan to begin developing apps in Django, and will be doing it on Github, in Github repositories. I really want to get down to the fundamentals of the structure of a Django project. I decided to do this by documenting the entire process from start to finish. So this may just be the first post in a series of posts on the topic.

Now that Django is installed, I go onto the next command. First, I want to make sure that I start my first Django project in the right directory. It doesn't really matter where I stick the project, but I have a special folder called "Refcards" where I am doing most of my development. So I will "cd" into that directory, to create the Django project I will be starting following the tutorial (all on the Django project website, accessible to anyone with a web browser and an Internet connection).

Once I am in the proper directory, I type this in the console:

$ django-admin startproject mysite

This creates/generates the basic "scaffolding" for my Django app.

In essence, this is what my last command generated, this directory structure with these files:

mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py

We will stop there for now and come back to this directory structure and these files, to see what they all mean.

I will quote directly from the Django project website, where I found this basic tutorial to build your first Django app:

These files are:

The outer mysite/ root directory is just a container for your project. Its name doesn’t matter to Django; you can rename it to anything you like.

manage.py: A command-line utility that lets you interact with this Django project in various ways. You can read all the details about manage.py in django-admin and manage.py.

The inner mysite/ directory is the actual Python package for your project. Its name is the Python package name you’ll need to use to import anything inside it (e.g. mysite.urls).

mysite/__init__.py: An empty file that tells Python that this directory should be considered a Python package. (Read more about packages in the official Python docs if you’re a Python beginner.)

mysite/settings.py: Settings/configuration for this Django project. Django settings will tell you all about how settings work.

mysite/urls.py: The URL declarations for this Django project; a “table of contents” of your Django-powered site. You can read more about URLs in URL dispatcher.

mysite/wsgi.py: An entry-point for WSGI-compatible web servers to serve your project. See How to deploy with WSGI for more details.

We will come back to this in a following post. That's it for now. The main idea, for now, is the directory structure and files that Django created for us, what I called the "scaffolding", namely:

mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py

Next we will look at these files and see what they are all about.

Tuesday, March 15, 2016

Quick Thoughts On How I Became A Programmer

Dear readers,

Quickly, I'd like to tell you how I came to be a computer programmer (with proverbial beginner status don't worry!). Basically, 5 or so years ago, I was surfing the web like anyone else, and I stumbled upon these MOOCs, we called them, these Massive Open On-line Courses.

The first MOOC I took, I think, was on the Udacity platform. I took a course that taught me Python all while building an actual, working search engine. It was a really great course. It effectively taught me how to write programs in the Python language.

Then, of course, I ended up taking over 100 different MOOCs on a variety of subjects. I wasn't happy just knowing how to write code in Python. I wanted to learn the ins and outs of Computer Science, both the Theoretical side and the Practical.

So that's what I did. Once I knew how Python worked, then I started trying to figure out what I was going to build. There comes that time, right, in the early day's of one's new life as a programmer where one must decide on some "project" of some sort.

In any case, I ended up fiddling and tinkering with all sorts of scripts, playing around with different modules and libraries in Python. I ended up playing with the Twitter Search API, feeling super amazed at what I could do with so few lines of code. It was truly an amazing experience.

Then slowly the projects started getting a little bigger in scope and in scale. I ended up writing my first real program in Python. I will take a break but will get back to the topic. Here, for your viewing pleasure, is my first ever ACTUAL PYTHON PROGRAM. And it works too! It is an implementation, in Python, of a Geomancy type reading. Look it up! (Google query: GEOMANCY).


 Here is another related script I wrote in Python. This one draws a random Geomantic Figure.

Without Further Ado - Some Python Resources To Get You Started

What The Python???!

Greatings, visitors! Simply put, this blog is meant as a place for me to write about what I've learned about Python in the last 5 years, since I first learned how to program in Python.

Mostly, I want this to be a repository, if you will, of the many wonderful modules, libraries, and frameworks etc. that I have experimented with, or else discovered, during my daily practice of coding in Python. For all intents and purposes, even after 5 years, I'm still just a beginner as far as programming goes. However, I have spent countless hours going through hundreds if not thousands of different repositories of Python code, so I feel that I have a pretty good idea of what is out there in terms of resources for Python programmers.

I have had introductions to other languages and in the end, I don't really like Python all that much, but the fact of the sheer numbers of Python programmers out there makes it a great community, one that I am otherwise happy to belong to.

Python, as you know, is a "high-level, general-purpose" programming language, amongst other things, and that's kind of what I don't like about it. I don't like things to be sugar-coated. I don't necessarily want to work at a higher level. I don't find Python code all that readable, no matter how good the original coder is or was. I think it looks like spaghetti no matter what you code up in Python.

Nevertheless, as I said, Python has a huge community of users, developers, programmers, et al, and that makes it a good thing to have, I guess, an "asset" if you must. But as soon as I find something closer to my real needs, I'll probably switch to something else. In that regard, I'm relatively "agnostic" as far as Python goes. It gets the job done, at least for now. I'm not a "loyalist", though. Again, as soon as something more fitting comes along, I'll be the first to jump off the Python Mothership.

In any case, none of that affects the fact that this blog is going to be about my discoveries in Python-Land. Hope you enjoy my Reflections on Python // Pythonic Reflections. Of course, an introduction to a blog about All Things Python would not be worth its salt if it didn't have a comical piece of actual Python code. And so here goes nothing...

def WhatIsPython(garbage):
                    return garbage