Learning Python and Django – PT I

A month ago I subscribe to a course from a Brazilian friend, Henrique Bastos, an awesome guy that knows a lot about Python and Entrepreneurship.
My goal with this course is to learn others programming languages, and in this case, Django is the Python framework for the Web, and I think that would be a good skill to have.
I don’t know anything about Python, the only skill that I have is with C++ and Qt, and isn’t an advanced skill. And here in Brazil, a lot of my friends knows Python, and always happen a discussion about wich programming is better and why. But for me build arguments like that I need to learn the language. To see its weakness and strengths.

I’m finishing the second module of the course. And in the last lessons, Henrique focus on the test. Everything that we need to implement to handle requests and a subscription form of our app, need to have a test first. Is the TAFT method: Test all the fucking time!

In a first moment I got pissed, why not go directly to implementation? But with the development of the app and the tests that I was writing, I started to see the importance of the tests. Funny is, that in college I’m doing a class called Software Engineer II, the current topic is about tests, and how the concept of the software tests is defined and wich kind of tests we need to do in a software.

This is an example of a class inside my, to check if a Post on the subscription form is valid or not:

class SubscribeInvalidPost(TestCase):
def setUp(self):
self.resp ='/inscricao/', {})

def test_post(self):
"""Invalid POST should not redirect"""
self.assertEqual(200, self.resp.status_code)

def test_template(self):
self.assertTemplateUsed(self.resp, 'subscriptions/subscription_form.html')

def test_has_form(self):
form = self.resp.context['form']
self.assertIsInstance(form, SubscriptionForm)

def test_form_has_errors(self):
form = self.resp.context['form']

I’m having some difficulties on the Python syntax. Since in all my short life like a programmer was using C/C++ or even Pascal(in the very beginning), I’m used to using the syntax of them. I got kind of upset after an if() that I forgot to add the ‘:’ in the end. >.<

However, so far, I like it a lot of this course, Henrique usually says that “Python comes with batteries”, that mean, Python has all the support on the API that you need, without the need to worry about what is happening below or to implement a new class to handle some specifications. And I’m learning that.

Django has an API called Forms, it’s a library only to handle formulary data. You can clean the data and have a dictionary returned with the cleaned data, you can validate all the data from the forms: If the data is an email, the Django already checks if is a valid email. Click here for the doc.

We are using Heroku, like the platform of deploy. And damn, it’s a hell of a tool. I hope in the future create more projects and update them to Heroku. You can work on everything on your localhost, and they configure Heroku, after that you can push to a branch inside Heroku platform, and it will install everything that you need for your project to run, build and put on the air. Easy like plug and play =D

A good thing to make clear is that Django is an API for backend in Python. To front-end, you can use everything that you like it. =D

Until the end of the course, I will finish a website with all database behind to handle subscriptions and manage of a hypothetical event.

I will continue to post about it, see you in the next post!

That’s all folks! =D




3 thoughts on “Learning Python and Django – PT I”

  1. Python is such a joy to program in, much more expressive and easy-to-read than C++. I’m looking forward to one day writing KDE programs in Python with Python bindings to the libraries.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s