Showing posts with label Django. Show all posts
Showing posts with label Django. Show all posts

Sunday, February 14, 2010

Using the Google App Engine Helper for Django

Working through the steps to install the Google Appengine Helper for Django, I zipped up Django 1.1 and placed it in the root directory. I ran, "python manage.py runserver" and got the following error :

dignan@dignan-laptop:~/workspace/python/[PROJECT_NAME]$ python manage.py runserver
ERROR:root:Django 1.0 or greater is required!

The solution was simple. I zipped up the "django" folder inside the complete distro and put it in the root.

Friday, November 20, 2009

Django properties for settings.py

I wanted to externalize all of the properties in settings.py for obvious reasons. I found a couple of suggestions.

What I did was create to files, properties_local.py and properties_dev.py. Working locally I imported, "import properties_local as properties"
# Django settings for [project name] project.
import properties_local as properties

and then set the variables accordingly:
DATABASE_ENGINE = properties.DATABASE_ENGINE
DATABASE_NAME = properties.DATABASE_NAME
DATABASE_USER = properties.DATABASE_USER
DATABASE_PASSWORD = properties.DATABASE_PASSWORD
DATABASE_HOST = properties.DATABASE_HOST
DATABASE_PORT = properties.DATABASE_PORT
I only have to change the import setting. I should figure out a way around that soon though.

Thursday, November 19, 2009

Django template does not exist

I got a really annoying error while putting up a new Django site:

TemplateDoesNotExist
at /flatpage/
flatpages/default.html
Request Method: GET
Request URL: http://[site url]/flatpage/
Exception Type: TemplateDoesNotExist
Exception Value:
flatpages/default.html
Exception Location: /usr/lib/python2.4/site-packages/django/template/loader.py in find_template_source, line 74
Python Executable: /usr/bin/python
Python Version: 2.4.3
Python Path: ['/[python path]', '/usr/lib/python24.zip', '/usr/lib/python2.4', '/usr/lib/python2.4/plat-linux2', '/usr/lib/python2.4/lib-tk', '/usr/lib/python2.4/lib-dynload', '/usr/lib/python2.4/site-packages']
Server time: Thu, 19 Nov 2009 22:39:37 -0500
Of course I had templates in Apache's directory. The Template-loader postmortem (great name) showed that Django was looking for the wrong directory (in italics below.)

Template-loader postmortem

Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.load_template_source:
/[development path]/flatpages/default.html (File does not exist)
Using loader django.template.loaders.app_directories.load_template_source:
/usr/lib/python2.4/site-packages/django/contrib/admin/templates/flatpages/default.html (File does not exist)
I know these things should be put into properties. I was being lazy.

I restarted the server to clear out whatever had cashed the older directory entry. Everything was fine.

Nice!

Tuesday, November 10, 2009

Django flatpages, templatetags and dynamic menus

One thing that Django's flatpages app is missing is a dynamic menu.

Coming from a Java background I am used to a huge user base and lots of open source code. The Django user base continues to meet my expectations.

I found this post detailing the creation of such a menu tag. I hadn't explored custom tags before anyway so I looked forward to trying it out.

I followed the instructions and got the following error :

TemplateSyntaxError at /menu/
'flatpage_menu' is not a valid tag library: Could not load template library from django.templatetags.flatpage_menu, No module named flatpage_menu
Request Method: GET
Request URL: http://127.0.0.1:8000/menu/
Exception Type: TemplateSyntaxError
Exception Value:
'flatpage_menu' is not a valid tag library: Could not load template library from django.templatetags.flatpage_menu, No module named flatpage_menu
Exception Location: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/template/defaulttags.py in load, line 927
Python Executable: /Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python
Python Version: 2.6.4
Python Path: ['/Users/jdavis/Documents/django_workspace/cantina76', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages']

The post was from last year. I was using the Django 1.1.1. I figured something had changed since his post.

I found a couple of references in Google Groups to this same example, but their suggestions didn't work for me.

The solution was to add my own app to INSTALLED_APPS and "from django import template" to the "flatpage_menu.py" file.

It worked fine after that.

Thursday, August 27, 2009

app-engine-patch Database problems

I've been using app-engine-patch to get some Django stuff running on Google AppEngine.

Several times my admin password has been reset or invalidated. On a couple of occasions I recreated the admin user from the link on the default page. After styling the site this wasn't possible.

I added the "create_admin_user" entry from the generated myapp/urls.py to the root level urls.py and manually entered the url. That worked.



Thursday, July 16, 2009

Practical Django Projects, coltrane weblog app and django-tagging

I'm working through Practical Django Projects 2nd Edition.

There is a problem with Chapter 4's weblog application, "coltrane." I won't go into detail about the coltrane app, but in the event that you encounter the same problem I've posted a solution.

I downloaded django-tagging. The current version was 0.2.1.

I created a symlink from my projects directory to the downloaded directory.

I added "'taggigng'" to "INSTALLED_APPS" and tried to start the server. I got the following :
Validating models...
Unhandled exception in thread started by <function inner_run at 0x652c30>
Traceback (most recent call last):
File "/Library/Python/2.5/site-packages/django/core/management/commands/runserver.py", line 48, in inner_run
self.validate(display_num_errors=True)
File "/Library/Python/2.5/site-packages/django/core/management/base.py", line 246, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Python/2.5/site-packages/django/core/management/validation.py", line 28, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/Library/Python/2.5/site-packages/django/db/models/loading.py", line 128, in get_app_errors
self._populate()
File "/Library/Python/2.5/site-packages/django/db/models/loading.py", line 57, in _populate
self.load_app(app_name, True)
File "/Library/Python/2.5/site-packages/django/db/models/loading.py", line 72, in load_app
mod = __import__(app_name, {}, {}, ['models'])
File "/[path to django projects]/coltrane/models.py", line 6, in <module>
from tagging.fields import TagField
File "/[path to django projects]/tagging/fields.py", line 10, in <module>
File "/[path to django projects]/tagging/models.py", line 9, in <module>
File "/[path to django projects]/tagging/managers.py", line 6, in <module>
ImportError: cannot import name parse_lookup
Sweet!

Turns out a lot of people have had this problem.

I checked out the current version from svn and recreated the symlink. All was well.

Django syncdb and create/drop

Django's manage.py syncdb command doesn't drop/create. It is clearly stated in the documentation. Naturally it took me a while to figure that out.

There is an easy solution :


python ./Documents/DjangoWorkspace/cms/manage.py reset coltrane
I've used it a few times now.


Tuesday, April 28, 2009

Where is the site-packages directory on Mac OSX?

/Library/Python/2.5/site-packages

Running :
 python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"

As suggested in the Django documentation displays the directory.