Very quickly, I’d like to introduce to you my newest github project – django-boilerplate-layout. It is my hope that for each new version of django, you can check out this project layout and just start coding. More info on what this project is on the README.markdown
Posts Tagged ‘python’
django-boilerplate-layout
Sunday, September 18th, 2011Session-Backed URL Redirect After Login with Django
Saturday, July 30th, 2011I am working on a Django-powered website, a website with no actual login of it’s own. I am using 3rd parties (Facebook/Twitter/etc) to provide authentication for my users. The issue I ran into is, what happens if a user goes to a url that is protected with a @login_requred decorator? Well, it should be simple – Django redirects the user to the supposed login page, with a parameter of next=/some/url/to/go/to. Since my app doesn’t do the login itself, the user then clicks on which third party service they wish to authenticate against. The user is taken through the third party’s authentication workflow and redirected back to my site. The problem here is that the “next” url parameter is lost in the process. I thought I would need to write a @login_required_session decorator, which would be less than ideal if my app then uses built in views with the @login_required decorator.
django-twitter-oauth on github
Thursday, June 16th, 2011Just a quick post to link (one of my) works in progress – django-twitter-oauth that I forked on github. It is a work in progress as I am using it on another project I’m working on currently so, hopefully, this app can only get better over time. There are a few things I may want to change (caching the access token in the session instead of always going to the DB) and, really, this has not been tested on MySQL yet (I am using sqlite3 for dev), but it should work. Works well so far. Only a few problems I have yet to start working on (off the top of my head, random BadStatusLine exception every once in a while, mainly) .
I will try to update my blog whenever I update the app with what I changed, but we’ll see.
Separating Out Django Models into Different Files
Monday, June 6th, 2011This will be a really quick post since, for whatever reason, I could not find this information out easy on the internet. The only reason I was able to find it is due to my great and good friend, Andres Buritica’s help. Starting a Django project, then an app gives you a models.py which Django expects to house all the models. This does not seem like the best of ideas, so obviously I want to split up the models into their own files in a specific model directory. To accomplish this, you must do two things:
- Create a meta class for the model with a field “app_label” being set to the name of your app
- In your __init__.py file, import that model.
For example, if you started an app by typing out ‘python manage.py startapp foo’, you can delete your models.py file, replace it with a directory named models (what I do), and inside have an __init__.py and Bar.py files.
in Bar.py:
from django.db import models class Bar(models.Model): bar = models.TextField(blank=False) class Meta: app_label = "foo"
then in __init__.py:
from Bar import Bar
This also goes for other things specified outside of the Django “norm” I guess?
If I wanted to associate Bar with the admin, I create a subdirectory inside my app named admin, and inside it I have
BarAdmin.py
from foo.models import Bar from django.contrib import admin admin.site.register(Bar)
Inside the __init__.py for the admin subdirectory, you’d have:
import BarAdminNow I could be doing this all wrong but this is the only way I managed to get everything working. If there is a better way to do this, I am all ears. To you Django/Python professionals out there, this may be common knowledge but I am noobing it up right now trying to better learn Python and Django.
Python, Threading and the Global Interpreter Lock
Friday, May 21st, 2010I am still heavy on my Python learning kick. One thing that’s always interested me is the Global Interpreter Lock and why Python doesn’t have “real” threading. I came across a talk given by David Beazley called “Mindblowing Python GIL” that was very informative. Pretty shocking really about how it works and very interesting. Obviously only watching this video would leave a bad taste in your mouth regarding Python and threading, so now I need to find another talk about why the GIL is good. There is a link in the comments to a slide show that talks about why it is good, but slides without the talk are almost useless for me.
Project Euler Problem 1
Wednesday, December 23rd, 2009So, I’m starting this much sooner than I would have anticipated but I suddenly got the urge to start.
Problem 1 is pretty straight forward:
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
Youtube is Turning Down the Lights
Wednesday, January 28th, 2009I couldn’t decide what to do tonight. It was either reading The Rum Diary by The Good Doctor, Hunter S. Thompson, or watch some Entourage. I am a huge fan of both. However I decided to do something that would expand my mind and entertain me.
