Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
What do you think about here lambda function to configure TEMPLATE_DIRS with relatives values ?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
klein.stephane@gmail.com  
View profile  
 More options Jun 30 2009, 7:38 am
From: "klein.steph...@gmail.com" <klein.steph...@gmail.com>
Date: Tue, 30 Jun 2009 04:38:32 -0700 (PDT)
Local: Tues, Jun 30 2009 7:38 am
Subject: What do you think about here lambda function to configure TEMPLATE_DIRS with relatives values ?
Hi,

When I configuration my TEMPLATE_DIRS in settings.py file, I use ever
"here" or
"here_cross" lambda function defined like this :

::

    import os
    here = lambda x: os.path.join(os.path.abspath(os.path.dirname
(__file__)), x)
    here_cross = lambda x: os.path.join(os.path.abspath(os.path.dirname
(__file__)), *x)

I can configure TEMPLATE_DIRS or MEDIA_ROOT like this :

::

    MEDIA_ROOT = ''

    TEMPLATE_DIRS = (
        # Put strings here, like "/home/html/django_templates" or "C:/
www/django/templates".
        # Always use forward slashes, even on Windows.
        # Don't forget to use absolute paths, not relative paths.
        here('myapp/templates'),
        here_cross(('otherapp', 'templates')),
    )

I suppose that this comment "Don't forget to use absolute paths, not
relative paths" is
relevant if I don't use "here" or "here_cross" function. If I don't
use it,
template paths are relative to current working directory and not to
"settings.py" file.

What do you think about this method (using here) ?
Why don't put "here" or/and "here_cross" in Django settings.py
skeleton ?

Note, I found here and here_cross tip on this page :
http://www.djangosnippets.org/snippets/445/

Thanks for your comment.
Regards,
Stephane


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
KLEIN Stéphane  
View profile  
 More options Jun 30 2009, 7:54 am
From: KLEIN Stéphane <klein.steph...@gmail.com>
Date: Tue, 30 Jun 2009 04:54:41 -0700 (PDT)
Local: Tues, Jun 30 2009 7:54 am
Subject: Re: What do you think about here lambda function to configure TEMPLATE_DIRS with relatives values ?
Sorry, I've some break line issue in my previous post.
This is my post cleaned.

Hi,

When I configuration my TEMPLATE_DIRS in settings.py file, I use ever
"here" or "here_cross" lambda function defined like this :

::

    import os
    here = lambda x: os.path.join(os.path.abspath(os.path.dirname
(__file__)), x)
    here_cross = lambda x: os.path.join(os.path.abspath(os.path.dirname
(__file__)), *x)

I can configure TEMPLATE_DIRS or MEDIA_ROOT like this :

::

    MEDIA_ROOT = ''

    TEMPLATE_DIRS = (
        # Put strings here, like "/home/html/django_templates" or "C:/
www/django/templates".
        # Always use forward slashes, even on Windows.
        # Don't forget to use absolute paths, not relative paths.
        here('myapp/templates'),
        here_cross(('otherapp', 'templates')),
    )

I suppose that this comment "Don't forget to use absolute paths, not
relative paths" is relevant if I don't use "here" or "here_cross"
function. If I don't use it, template paths are relative to current
working directory and not to "settings.py" file.

What do you think about this methode (using here) ?
Why don't put "here" or/and "here_cross" in Django settings.py
skeleton ?

Note, I found here and here_cross tip on this page :
http://www.djangosnippets.org/snippets/445/

Thanks for your comment.
Regards,
Stephane


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael  
View profile  
 More options Jun 30 2009, 9:27 am
From: Michael <newmani...@gmail.com>
Date: Tue, 30 Jun 2009 09:27:26 -0400
Local: Tues, Jun 30 2009 9:27 am
Subject: Re: What do you think about here lambda function to configure TEMPLATE_DIRS with relatives values ?

On Tue, Jun 30, 2009 at 7:54 AM, KLEIN Stéphane <klein.steph...@gmail.com>wrote:

If it works for you, it works. Personally I find lambdas a little difficult
to read, and personally in this situation, I just put:
os.path.normpath(os.path.join(os.path.dirname(__file__), 'otherapp',
'templates'))

inside of TEMPLATE_DIRS directly. I find that clearer to see what is
happening, it is all in one line and still really simple.

But what works for you works for you.

Michael


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Darryl Ross  
View profile  
 More options Jun 30 2009, 11:28 am
From: Darryl Ross <dar...@afoyi.com>
Date: Wed, 01 Jul 2009 00:58:04 +0930
Local: Tues, Jun 30 2009 11:28 am
Subject: Re: What do you think about here lambda function to configure TEMPLATE_DIRS with relatives values ?

Hi Stephane,

I think it is a great idea. The lambda trick means I don't have to make
any changes at all to switch between my development environment and
production. A real life example from a current project:

-----

from os.path import abspath, dirname, join
APP_PATH = lambda *x: abspath(join(dirname(__file__), *x))

MEDIA_ROOT = APP_PATH('webroot', 'media')
TEMPLATE_DIRS = (
    APP_PATH('templates'),
)

-----

Note the * on the definition for x which means you only need one lambda.

On my production machines, the websites typically run from

/home/httpd/<domain>

but on my development machine (my laptop), they run from

/home/darryl/devel/websites/<customer>/<domain>

Cheers
Darryl

  signature.asc
< 1K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »