Missing basedir/apps in sys.path?

Submitted by Guilherme Salgado on Feb. 2, 2011, 7:16 p.m.

Details

Message ID 1296674170.2552.31.camel@feioso
State Superseded
Headers show

Commit Message

Guilherme Salgado Feb. 2, 2011, 7:16 p.m.
Hi there,

I've just followed the instructions to deploy patchwork and everything
seemed to work fine but when I went to /admin on my browser I got the
following error:

  TemplateSyntaxError: Caught ImportError while rendering: No module named patchwork

Which seems to happen because templates reference the patchwork module
directly (e.g. 'patchwork.views.') but in patchwork.wsgi only the
basedir is added to sys.path, so you'd in fact have to reference that
using 'apps.patchwork.views', so I was wondering if the patch below
would make sense?

Cheers,

Comments

Dirk Wallenstein Feb. 3, 2011, 11:04 a.m.
Hi,

On Wed, Feb 02, 2011 at 05:16:10PM -0200, Guilherme Salgado wrote:
> Hi there,
> 
> I've just followed the instructions to deploy patchwork and everything
> seemed to work fine but when I went to /admin on my browser I got the
> following error:
> 
>   TemplateSyntaxError: Caught ImportError while rendering: No module named patchwork
> 
> Which seems to happen because templates reference the patchwork module
> directly (e.g. 'patchwork.views.') but in patchwork.wsgi only the
> basedir is added to sys.path, so you'd in fact have to reference that
> using 'apps.patchwork.views', so I was wondering if the patch below
> would make sense?
> 
> Cheers,
> 
> --- a/lib/apache2/patchwork.wsgi
> +++ b/lib/apache2/patchwork.wsgi
> @@ -11,6 +11,7 @@ import sys
>  
>  basedir = os.path.dirname(__file__)
>  sys.path.append(basedir)
> +sys.path.append(os.path.join(basedir, 'apps'))
>  
>  os.environ['DJANGO_SETTINGS_MODULE'] = 'apps.settings'
>  import django.core.handlers.wsgi

Looks good.
However, I find it a bit confusing to construct a path that relies on
the fact that this module is found through a symlink.  I would hardcode
'/srv/patchwork' and '/srv/patchwork/apps' like in the mod_python
config.  Or would it be possible to get rid of the symlink
'/srv/patchwork/patchwork.wsgi' when changing it in
apache2/patchwork.wsgi.conf and then optionally construct the paths
relative from the real location?

Patch hide | download patch | download mbox

--- a/lib/apache2/patchwork.wsgi
+++ b/lib/apache2/patchwork.wsgi
@@ -11,6 +11,7 @@  import sys
 
 basedir = os.path.dirname(__file__)
 sys.path.append(basedir)
+sys.path.append(os.path.join(basedir, 'apps'))
 
 os.environ['DJANGO_SETTINGS_MODULE'] = 'apps.settings'
 import django.core.handlers.wsgi