Geek Garage

Find inspiration in awesome ideas.

Tag: Python

Setup Django on OS X

Installing Django on OS X is just as easy as any other Python library or framework. It is just a one line command as it is described in the Django documentation. But if you have an all-new OS X system, you don’t have all the tools installed. Pip is not part of the standard system, but installing also straightforward and you just have to follow the documentation. This post is a reminder for all the steps.

To download the pip-installer, the preferred way on OS X is by using curl:

curl -O https://bootstrap.pypa.io/get-pip.py

You can install pip using this installer. Be aware that you’ll need the administrator privileges.

sudo python get-pip.py

Now you can install Django as it is described in the documentation which was version 1.7.1 at the time of writing this post.

sudo pip install Django==1.7.1

You can finally check if the installation is successful in a Python console

>>> import django
>>> print(django.get_version())
1.7.1

As you see, no tricks here. All the documentations are correct so everything should be ready in less than 5 minutes. Hope that if you find this post, it will have saved you the extra minute to search trough the different docs.

Modifying a Django Model

We fulfilled the first user story, but we revealed a weakness in our model. Of course this specific situation could have been prevented. But as a lot of weaknesses are revealed during testing, we have to know how to go back to your model. Lets see the consequences on this simple case.

At this stage, a product owner should add a new task which should be “Submitting duplicate data should be rejected with an informative message“. As we observed in the previous post, duplicate SourceUrls share the same URL. So, lets resolve this issue.

Read More

Create your first SourceUrl object.

We have defined our model and created the database tables. But we still didn’t completed the User Story we’ve defined. Using Django, having our model, we’ll just let the framework do the job.

Other frameworks like Ruby on Rails and Grails follow the Convention over Configuration paradigm for that purpose. Django is a little different. Instead of providing a scaffold for forms and display pages, it do provide an entire backend, the admin site.

Read More

Define the models of your RSS reader

Once the project is created, we can focus on its features. Now, we can define our first User Story. In the purpose of our project, we’ll want to follow RSS feeds. We’ll need to inform our software about those feeds. Usually, the first User Story is “I want to see a form to submit my data“. Usually, to complete this User Story, developers focus on the form. That is not the approach with Django. The data is most important than the form, so we’ll start with the data, Django will make the rest much easier.

Django also makes the data manipulation easy with the Model Layer. This is the abstraction layer where you are going to define and manipulate your data model. So first we have to define and tell Django what our data is.

At this step, we plan to build an app which will load, parse and display RSS feeds. So, the system will need to know where to find the feeds, and then to parse all the items. The user should just have to provide the URL of the feed. This will be our first model and form. A very simple model which will let us see how Django deals with it.

Read More

Working with Django and Eclipse.

Before going further on the development of our RSS reader app, lets just have a quick look about the how to work on the project with Eclipse. Actually, if you are planning to dedicate your life to Python and web development, Aptana Studio is certainly a better choice as it is an Eclipse ready to use. But if you want to build your own IDE with the plug-ins of your choice, you’ll certainly use Eclipse. But Eclipse does not support Python out of the box. As I introduced the tools in the first post of this tutorial, you’ll need to add the PyDev plug-in which will give you all the features you need. The manual and especially the Getting Started chapter provides a good explanation about how to configure the plug-in.

The manual also explains how to create a new project and how to import one. There is also a specific page for Django. If you followed the previous step of the tutorial, you already have created the project sources and you’ll need to import them. To understand why and how, lets just see how you would have done directly from Eclipse.

Read More

Start your own RSS reader project, part 2.

So, in the previous post, you have gathered all the tools you need. You can now focus on the project. Thus, before defining our User Stories, we need to create the project. This will start by initiating a project trough Django. This step is nicely described on the Django Tutorial, so in this post, we’ll focus on our specific need. It will be necessary to understanding the terminology used by Django and more specifically what is a Project and what is an Application.

Read More

How to read RSS online ? Make your own site with Python and Django

What is the worst news we heard lately ? Yes, Google is closing Google Reader, which is a major disaster in our lives. How can we read our RSS feeds by now (actually, by the 1st of July) ? Watching the numbers of flowers on Google Reader’s grave, this was still a popular service.

But hey, you are techies, and RSS feeds are simple data easy to parse, so, why don’t you write your own reader page instead of wasting time looking for another service provider ? Of, course, you don’t want to spend too much time on this. Ok, lets do it the easy way, do you know Python and Django ? If not, lets learn how to use them.

Read More

Reuse your Mir:ror in Pyhton

The Mir:ror is an RFID reader produced by the company Violet, which also produced the Nabaztag. With the idea of the Internet of Things in mind, this device is a mass-market RFID reader really easy to use. You just have to connect it to your computer via USB, and associate any RFID tag to an action trough Violet’s website.

But here is the problem. Since the service is hosted on a remote server run by a service provider, how can you be sure of how long the service will be provided ? The company Violet does not exist anymore, so the device had become useless.

Read More

Make your computer talk to your Arduino, in Python.

At Europython 2012, I attended a talk about Python and the Arduino which motivated me to make my computer talk to my Arduino. Actually, using Python, it is pretty straightforward. This would bring some opportunities to have a real interaction between the computer and the physical world.

Read More

Powered by WordPress & Theme by Anders Norén