Sunday, January 13, 2013

Django Setup on Hostgator Part 1

It is Sunday and I am excited to get django installed and running ronaldsnyder.net hosted by hostgator.   I have zero experience with Django or any web frame work.  I have found an official Django tutorial on their website and a guide on what need done specific to Hostgator.

The beginning of the tutorial worked just fine.  The first issue I had was getting a DoesNotExist error at ronaldsnyder.net/admin when I tried testing.  I found a post on stackoverflow that suggested logging into the intereactive prompt and recreating (in my case creating) the site through the intereactive shell.  

python manage.py
from django.contrib.sites.models import Site
Site.objects.create(pk=1, domain='www.ronaldsnyder.net', name='ronaldsnyder.net)

That solved that problem and now I have a working admin panel!  




I believe this problem was because the tutorial assumed you were working off from the built in test web server that comes with Django and not a real domain.  But wait....why isn't there any formatting or CSS?  It appears it is the way that Django deals with static files.  Some of this is handled by the development server but since I went with a live server right away I am running into some things not covered yet in the tutorials.  I am starting to think that I should have started with the dev server too....

After banging my head against the wall for a while I came up with this solution.  Find the css files included with django and find the path of the css.  So here is the path to the css when looking at the source:
href="/static/admin/css/base.css"
href="/static/admin/css/dashboard.css"

After some searching I found the media files at:

/usr/lib/python2.6/site-packages/django/contrib/admin/media which had the css, img and js directories.

I copied the css, img and js directories into ~/public_html/static/admin. BAM!!!! We have a formatted login page! I don't feel this is probably the correct way but it fixed my issue for now.






So the next thing I did was try to login to the admin panel but it seems we have another issue.  When I was doing the initial setup it appeared to me that the creation of the superuser failed but I continued on with the Django tutorial.  So now I try to create the superuser manually according to the Django documentation and I get TypeError: decode() argument 1 must be string, not None





I did some searching and found that this a bug from the locale not being set.  I was able to set the locale and fix the issue by running the following commands in the Hostgator session I had up:


export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

python manage.py createsuperuser --username=USERNAME

I have made it through page one of the Django tutorial and brushed upon the 2nd and it has taken me a lot more time than I expected. I thought I would get through the entire tutorial today. I have found Django a bit overwhelming so far but not unexpected.

**Edit February 2nd, 2013.  I would not recommend doing it this way.  I would set this up on my your local computer first and do the testing.  I would also use Eclipse with the PyDev plug in.  Take a look at http://ronsnyder.blogspot.com/2013/02/using-pydev-for-django.html for more information on why.





No comments:

Post a Comment