download Django-1.0.tar.gz
cd Downloads
tar xf Django-1.0.tar
rm Django-1.0.tar
cd Django-1.0
sudo python setup.py install
This created
I added this to my .bashrc file:
# Set up Django
if [[ -d /Library/Python/2.5/site-packages/django/bin ]]; then
PathAdd /Library/Python/2.5/site-packages/django/bin
fi
There is an out-of-date Django tutorial on the Django Web site, but it was converted into the better Django Book.
I chose to learn Eclipse/PyDev at the same time that I was learning Python/Django. The good part about this is that I got to learn about Eclipse and PyDev. The bad part is that at various spots in the tutorial, I had to replace 'mysite' with 'src'.
I created the tutorial mysite project with Eclipse->Window->Open Perspective->Other... and PyDev, then File->New->PyDev Project. I set the Project name to mysite, the python version to 2.5, and I left the Create default 'src' folder and add it to the pythonpath? box checked. This created ~/eclipse/workspace/mysite/src, but it's empty. Per the tutorial, I created a project there named mysite by doing
cd ~/eclipse/workspace/mysite/src
django-admin.py startproject mysite
Over in Eclipse, I highlighted the mysite->src
folder and did File->Refresh.
To verify that this worked, I did
cd /Users/siemsen/eclipse/workspace/mysite/src/mysite
python manage.py runserver
This worked, but we want to be able to run the server from from within Eclipse, so highlight the manage.py tab and do Run->Run. Set the run type to Python Run. It'll run manage.py without arguments and show the results in the Consale window. You'll see a "usage" message from manage.py. To make it run correctly, select Run Run Configurations.... Click the Arguments tab and set the arguments to Program arguments to "runserver --noreload". Once it's running, the Django server automatically re-reads the project files, so we won't need to restart it via "Run" as we would when developing a regular program, but it's nice to have it integrated correctly.
I edited the settings.py file to set these:
DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = os.path.join(os.path.dirname(__file__), 'contacts.db').replace('\\','/')
To create database tables, I did
python manage.py syncdb
and answered the prompts to create a superuser named 'siemsen' with
the ski thing password.
To verify that my sqlite3 database contained the new Django tables, I did
sqlite3 contacts.db
.schema
To create an app, I did
python manage.py startapp books
...which created a books directory.
In chapter 5 of the book, in the "Your First Model" section, when you run "python manage.py validate", you'll get errors about "unexpected keyword argument maxlength". You have to change all occurrences of "maxlength" to "max_length". That'll fix one error, but then you'll get errors about a missing Python Imaging Library. I went to the Web site mentioned in the error message and downloaded Imaging-1.1.6.tar. Then I did
cd /Users/siemsen/Downloads/Imaging-1.1.6
tar xvf Imaging-1.1.6.tar
cd Imaging-1.1.6
sudo python setup.py install
cd ..
rm -rf Imaging-*
... and then "python manage.py validate" returned
"0 errors found".
...
In section 2 of the tutorial, where they explain about templates, I did
mkdir -p ~/django/my-templates/admin
mkdir ~/django/my-templates/admin
cp /Library/Python/2.5/site-packages/django/contrib/admin/templates/admin/base_site.html .
So I figure now is as good a time as any to plug the SNMP scripts I've written in Python. It turns out netserver has SNMP access to the FRGP switches, so it's easy to run the command line stuff there. As a quick check, you can run tests inside of the Python interpreter. Or write an actual script incorporating the tests you want.
There are no real docs, but the files themselves have a fair amount of comments in them. It's all in CVS, so you can check out a copy or browse by following the CVS docs on netserver: http://netserver.ucar.edu/nets/tools/cvs/
For example, here's test which verifies that trunk configurations are the same on both ends. The function returns a list of trunk ports whose ends do not match:
netserver@ML $ python
Python 2.1.3 (#1, Sep 7 2002, 15:29:56)
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import catalyst
>>> catalyst.CheckTrunkEnds('l3-gs-1.frgp.net','frgprat')
['2/1', '3/1']
>>> catalyst.CheckTrunkEnds('frgp-gs-1.frgp.net','frgprat')
['1/2', '3/2', '2/2']
>>> catalyst.CheckTrunkEnds('frgp-es-1.frgp.net','frgprat')
['2/49']
>>>