« ugh!Thank you Linux Mint!!! »

Monday, April 6th, 2009

I Want My Django Path

Categories: Computers

I use Windows XP at work, and various Linux distributions at home. I started using Django at work, so I got accustomed to finding django in

C:\Python25\Lib\site-packages\django\

Now I recently started using git a lot, so I could do work from home without having to email zipped up files that make an application. Another thing to help keep my development environments extremely similar, I have a module called 'apps' where I keep frequently used 3rd party apps, like Eric's seamlessly put together django-pagination app. So in switching to Linux and finally getting my act together with using my non Windows boxes, I realize, I can't find django. First, in both Debian and Ubuntu when you install django with apt, it makes django-admin without the .py at the end. pretty confusing for Linux newbies.

Anyway, I finally located django in this path:

/var/lib/python-support/python2.5/django/

Can you see where I would be confused? Anyway, I threw this into the init.py within that django directory.

def get_path():
    import os
    return os.path.dirname( os.path.realpath( file ) )

Now since apt-get install python-django put all the right paths in all the right places, and everything points to where it needs to be, all you have to do to know where to explore django is open up a python terminal and type three easy lines.

brandon@dell:$ python
Python 2.5.2 (r252:60911, Jan  4 2009, 17:40:26) 
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.get_path()
'/var/lib/python-support/python2.5/django'
>>> 

I'm going to submit this to django at some point, but maybe someone can comment on this if there is a totally obvious way to find out the path to django modules that I don't know about already.

edit: After testing this in Windows, I see that it can only be used as a visual aid (which was the main purpose behind it anyway), because it imports the path with the escape characters '\\' instead of a single '\'

I am certain you can edit the script to join on the path separator, but I want to go to bed. I will update this script to work in BOTH OS (I have no way to test a Mac, but assume it works correctly as it would in Linux).

permalink 1:16am by Brandon //2 comments 1176 views

2 comments

Comment from: Lu [Visitor]
You could just use:
>>>import django
>>>django.__file__
01/14/10 @ 16:35
Comment from: Brandon [Member] Email
thanks! you're my first helpful comment ever. i'm new at this, so i'm posting what i do to see if people can guide me in a better direction.
01/14/10 @ 17:15

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)

©2010 by Brandon Contact design by brandonh

Credits: blogtool | dedicated hosting | evoTeam

visits: stats