lost with django-pki am I stupid ?

143 views
Skip to first unread message

Mat

unread,
Dec 3, 2010, 3:43:12 PM12/3/10
to django-pki
Hello,

I tried at least 2 hours to make django-pki work on my pc, I must
confess that that I didn't manage.

What I manage to get:

Traceback (most recent call last):
File "/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py",
line 280, in run
self.result = application(self.environ, self.start_response)
File "/usr/lib/pymodules/python2.6/django/core/servers/basehttp.py",
line 674, in __call__
return self.application(environ, start_response)
File "/usr/lib/pymodules/python2.6/django/core/handlers/wsgi.py",
line 241, in __call__
response = self.get_response(request)
File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py",
line 141, in get_response
return self.handle_uncaught_exception(request, resolver,
sys.exc_info())
UnboundLocalError: local variable 'resolver' referenced before
assignment

I tried to follow the cryptic readme (for a non django fluent).

A step by step help would be very welcome !

Cheers.

Matthieu

Daniel Kerwin

unread,
Dec 4, 2010, 4:38:42 AM12/4/10
to django-pki
Hi Matthieu,

can you please give me more informations:

- What version are you using?
- WSGI or the development server?
- In case it's WSGI have you updated django.wsgi?

Cheers,

Daniel

Max Arnold

unread,
Dec 4, 2010, 7:41:21 AM12/4/10
to django-pki
On Fri, Dec 03, 2010 at 12:43:12PM -0800, Mat wrote:
> Hello,
>
> I tried at least 2 hours to make django-pki work on my pc, I must
> confess that that I didn't manage.
>
> What I manage to get:
>
> UnboundLocalError: local variable 'resolver' referenced before
> assignment

Probably (just a guess) you haven't defined Django url configuration. Below is simple step-by-step guide. It is not intended for production deployment, but hopefully should give you something functional to play with.

8<------------------------------------------------------------------------------

Create new django project (assuming Django-1.2.x is already installed):
$ django-admin.py startproject django_pki_testsite

Grab the latest source code:
$ git clone git://github.com/dkerwin/django-pki.git

For testing purposes just copy django-pki application to our test project:
$ cp -r django-pki/pki django_pki_testsite/

Create certificate storage directory:
$ cd django_pki_testsite
$ mkdir PKI

Edit settings.py:

1. For convenience, at the top add:

import os
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))


2. Configure database (for testing purposes sqlite is enough):

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.abspath(os.path.join(PROJECT_PATH, 'pki.db')),
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}


3. Configure path to media files and url prefixes:

MEDIA_ROOT = os.path.join(PROJECT_PATH, 'pki', 'media')

MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = '/admin_media/'


4. Register pki application and enable admin interface:

INSTALLED_APPS = (
# these are default for django-1.2.x
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',

# and these are required for django-pki
'pki',
'django.contrib.admin',
)


5. Set certificate storage directory:

PKI_DIR = os.path.join(PROJECT_PATH, 'PKI')


Now edit urls.py to look like this:

from django.conf.urls.defaults import *
from django.contrib import admin
from django.conf import settings

admin.autodiscover()

handler500 = 'pki.views.show_exception'
handler404 = 'pki.views.show_exception'

urlpatterns = patterns('',
(r'^', include('pki.urls')),
(r'^admin/', include(admin.site.urls)),
)

# This is useful only for Django development web server:
if settings.DEBUG:
M = settings.MEDIA_URL
if M.startswith('/'): M = M[1:]
if not M.endswith('/'): M += '/'
urlpatterns += patterns('',
(r'^%s(?P<path>.*)$' % M,
'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT,
'show_indexes': True}),
)

Configuration complete. Next, let Django create necessary database tables:

$ python manage.py syncdb

and specify default superuser account when asked. Then launch development webserver:

$ python manage.py runserver

and point your browser to http://localhost:8000/admin/

8<------------------------------------------------------------------------------

If you want to use Django-PKI in production, it is better to use Apache with mod_wsgi and mysql/postgresql database. Read some docs about Django deployment and feel free to ask for help if you have any troubles.

Hope this helps.

Max Arnold

unread,
Dec 4, 2010, 9:10:35 AM12/4/10
to django-pki
On Sat, Dec 04, 2010 at 06:41:21PM +0600, Max Arnold wrote:

To be more compliant with current README, there are several minor corrections:

> 5. Set certificate storage directory:
>
> PKI_DIR = os.path.join(PROJECT_PATH, 'PKI')
>

6. Add exception logging middleware:

MIDDLEWARE_CLASSES = (
# these are default:
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',

# this middleware is required for pki exception logging:
'pki.middleware.PkiExceptionMiddleware',
)

Also there are bunch of optional settings to tweak, but default values are just fine. For example, you may want to change TIME_ZONE and LANGUAGE_CODE, plus add PKI_DEFAULT_COUNTRY according to your location.


> Now edit urls.py to look like this:
>
> from django.conf.urls.defaults import *
> from django.contrib import admin
> from django.conf import settings
>
> admin.autodiscover()
>
> handler500 = 'pki.views.show_exception'

This 404 handler line is unnecessary:

Reply all
Reply to author
Forward
0 new messages