Loading ...
Sorry, an error occurred while loading the content.

[Cheetahtemplate-discuss] Problem with import from custom directory (was Re: Problem with import in web-app)

Expand Messages
  • Webb Sprague
    I don t think the problem is with mod_python. My question is now: How do I gracefully update sys.path to include a directory not in the standard python path?
    Message 1 of 2 , Sep 13, 2007
    • 0 Attachment
      I don't think the problem is with mod_python. My question is now:

      How do I gracefully update sys.path to include a directory not in the
      standard python path? I want to import a module to use some constants
      in place holders. EG:

      #sys.path.append(/foo)
      #import bar ## in /foo
      <h1>the magic number is $foo.baz + 1 </h1>

      However, this doesn't work, throwing an error that bar is not found.
      I am resigned to compiling my cheetah templates and then editing the
      *.py files, but this seems bad.

      Thanks!
      W

      -------------------------------------------------------------------------
      This SF.net email is sponsored by: Microsoft
      Defy all challenges. Microsoft(R) Visual Studio 2005.
      http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
      _______________________________________________
      Cheetahtemplate-discuss mailing list
      Cheetahtemplate-discuss@...
      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
    • Dirk van Oosterbosch, IR labs
      Hi, I think I had a similar problem: have your templates in a separate directory, and want to use and import stuff in the templates, from other directories (in
      Message 2 of 2 , Sep 16, 2007
      • 0 Attachment
        Hi,

        I think I had a similar problem:
        have your templates in a separate directory, and want to use and import stuff in the templates, from other directories (in my case the directory in which the mod_python PythonHandler(s) live).

        My solution is have mod_python import the path.
        (if you have mod_python 3.3)

        <IfModule mod_python.c>
        PythonOption mod_python.importer.path "['/home/dirk/www/python', '/home/dirk/www/python/templates']"
        SetHandler ...
        PythonHandler ... 
        ...

        (And the mod_python.importer.path will automatically reload your modules or templates if they are modified –and the template compiled–)

        HTH
        dirk

        On 14-sep-2007, at 6:50, Webb Sprague wrote:

        I don't think the problem is with mod_python.  My question is now:

        How do I gracefully update sys.path to include a directory not in the
        standard python path?  I want to import a module to use some constants
        in place holders.  EG:

        #sys.path.append(/foo)
        #import bar ## in /foo
        <h1>the magic number is $foo.baz + 1 </h1>

        However, this doesn't work, throwing an error that bar is not found.
        I am resigned to compiling my cheetah templates and then editing the
        *.py files, but this seems bad.

        Thanks!
        W



        -----------------------------
        Dirk van Oosterbosch
        de Wittenstraat 225
        1052 AT Amsterdam
        the Netherlands

        -----------------------------


      Your message has been successfully submitted and would be delivered to recipients shortly.