Template Variables

2020-03-31 Thread aetar
I am writing a simple web app, and I am struggling to access my variable 
attributes in one of my templates. The get_object_or_404 method returns my 
customized 404 error from my *content_detail.html *file: "No content is 
available." 

Here are my files:

*archive/archive/urls.py:*

from django.contrib import admin
from django.urls import include, path
from django.views.generic import RedirectView
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
path('posts/', include('posts.urls')),
path('admin/', admin.site.urls),
path('', RedirectView.as_view(url='posts/', permanent=True)),] + 
static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

*archive/posts/urls.py:*

from django.urls import path

from . import views

app_name = 'posts'

urlpatterns = [
path('', views.index, name='index'),
path('/', views.ContentDetailView.as_view(), 
name='content-detail'),
]

*archive/posts/models.py:*

import datetime

from django.db import models
from django.utils import timezone
import uuid

class Content(models.Model):
content_head = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')

class Meta:
verbose_name_plural='contents'

def __str__(self):
return self.content_head

def get_absolute_url(self):
return reverse('detail', args=[str(self.id)])

class ContentInstance(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, 
editable=False)
content = models.ForeignKey(Content, on_delete=models.SET_NULL, 
null=True)
content_body = models.TextField()

def __str__(self):
return f'{self.id}, {self.content.pub_date}'

*archive/posts/views.py:*

from django.shortcuts import render, get_object_or_404

from .models import Content, ContentInstance
from django.views import generic

def index(request):
archive_list = Content.objects.order_by('-pub_date')[:5]
context = {'archive_list': archive_list}
return render(request, 'posts/index.html', context)

class ContentDetailView(generic.DetailView):
model = Content

def content_detail_view(request, primary_key):
content = get_object_or_404(Content, pk=primary_key)
return render(request, 'posts/detail.html', context={'content':content})

*archive/posts/templates/posts/index.html:*




  Title


  Heading
 {% if archive_list %}
 
  {% for content in archive_list %}
{{ content.content_head 
}}({{ content.pub_date }})
  {% endfor %}
  
  {% else %}
  No content is available.
  {% endif %}



*archive/posts/templates/posts/content_detail.html:*




  Title


  Heading
 
 {% if content %}
   {% for contentinstance in content.contentinstance_set.all %}
{{ content.pub_date }}
   {{content.content_body}}
   {% endfor %}
 {% else %}
 No content is available 
 {% endif %}
 



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b86505fd-b149-48fd-a01f-b3938cb2b880%40googlegroups.com.


Re: Template variables not showing up in web-page

2015-10-24 Thread CTA2052
Thank you for the very speedy reply. I really apprceciate that.  Actually I 
had tried the page/file name in place of the path as well and it still 
would not work. What it turned out to be is, on the back end of a reboot 
(because I took a break to up the memory on my macbook pro,) I rebooted and 
it then worked. Not sure why a reboot fixed it, but it did, just in case 
anyone else has the same problem in the future, that is what worked for me.
Thanks all!
CTA

On Friday, October 23, 2015 at 3:51:57 PM UTC-4, CTA2052 wrote:
>
> Hello All,
>
> This may be the most basic question to ask and believe me it does not come 
> without much research and frustration, but I just can't seem to make it 
> work. So I do apologize ahead of time for even having to post it. I am very 
> new to django (2-months), python(4-months) and in fact programming in 
> general. I have reviewed the online doc sevral times now and various books 
> and tutorials trying to find the answer.
>
> However, I can't seem to get my template variables to render within the 
> web page (crazy I know).
>
> I've tried this many different ways and finally backed-up and 
> stripped-down the code to see what it is I'm missing
>
> *Here is what I have right now in the veiw:*
>
> def response_page(request):
>   
> myv = " fun fun fun "
> context = {'affirmation': myv}
> return render('/response_page/', context )
>
>
> *Here is the template:*
>
>
> 
>
> {% extends "base.html" %}
> {% load static %}
> {% load crispy_forms_tags %}
>
> 
> 
> 
> challenge_engine_response
> 
> 
> {% block content %}
> Testing 1,2,3
>
>
>  I am having so much {{ affirmation }}   
>
> Back to Home Page
>
> 
> {% endblock %}
> 
>
>
> Everything shows up as expected except the variable "affirmation"  which 
> of course should render as "fun fun fun".
>
> I am sure I am missing something silly, but what?
> Thanks in advance for the help.  I have very little hair left at this 
> point (ha).
>
> Thank you all!
>
> Humbly yours,
> CTA2052
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/69ee2f23-f96b-4e4e-90af-cdba160d8dc6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Template variables not showing up in web-page

2015-10-23 Thread Dheerendra Rathor
signature for request is render(request, template_name, context, **kwargs)

So it should be like render(request, 'response_page.html', context=context)

On Sat, 24 Oct 2015 at 01:21 CTA2052  wrote:

> Hello All,
>
> This may be the most basic question to ask and believe me it does not come
> without much research and frustration, but I just can't seem to make it
> work. So I do apologize ahead of time for even having to post it. I am very
> new to django (2-months), python(4-months) and in fact programming in
> general. I have reviewed the online doc sevral times now and various books
> and tutorials trying to find the answer.
>
> However, I can't seem to get my template variables to render within the
> web page (crazy I know).
>
> I've tried this many different ways and finally backed-up and
> stripped-down the code to see what it is I'm missing
>
> *Here is what I have right now in the veiw:*
>
> def response_page(request):
>
> myv = " fun fun fun "
> context = {'affirmation': myv}
> return render('/response_page/', context )
>
>
> *Here is the template:*
>
>
> 
>
> {% extends "base.html" %}
> {% load static %}
> {% load crispy_forms_tags %}
>
> 
> 
> 
> challenge_engine_response
> 
> 
> {% block content %}
> Testing 1,2,3
>
>
>  I am having so much {{ affirmation }}   
>
> Back to Home Page
>
> 
> {% endblock %}
> 
>
>
> Everything shows up as expected except the variable "affirmation"  which
> of course should render as "fun fun fun".
>
> I am sure I am missing something silly, but what?
> Thanks in advance for the help.  I have very little hair left at this
> point (ha).
>
> Thank you all!
>
> Humbly yours,
> CTA2052
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5f78b5c5-0652-479f-9ffc-8cd2604967b8%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/5f78b5c5-0652-479f-9ffc-8cd2604967b8%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAByqUgjzhF-36x11T%3DZocVhsRcE71N_nd6grtTRZAMkdq5KRsw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Template variables not showing up in web-page

2015-10-23 Thread CTA2052
Hello All,

This may be the most basic question to ask and believe me it does not come 
without much research and frustration, but I just can't seem to make it 
work. So I do apologize ahead of time for even having to post it. I am very 
new to django (2-months), python(4-months) and in fact programming in 
general. I have reviewed the online doc sevral times now and various books 
and tutorials trying to find the answer.

However, I can't seem to get my template variables to render within the web 
page (crazy I know).

I've tried this many different ways and finally backed-up and stripped-down 
the code to see what it is I'm missing

*Here is what I have right now in the veiw:*

def response_page(request):
  
myv = " fun fun fun "
context = {'affirmation': myv}
return render('/response_page/', context )


*Here is the template:*




{% extends "base.html" %}
{% load static %}
{% load crispy_forms_tags %}




challenge_engine_response


{% block content %}
Testing 1,2,3


 I am having so much {{ affirmation }}   

Back to Home Page


{% endblock %}



Everything shows up as expected except the variable "affirmation"  which of 
course should render as "fun fun fun".

I am sure I am missing something silly, but what?
Thanks in advance for the help.  I have very little hair left at this point 
(ha).

Thank you all!

Humbly yours,
CTA2052

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5f78b5c5-0652-479f-9ffc-8cd2604967b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Should I use 'locals()' or create a dictionary with the template variables? What is better?

2014-07-17 Thread Russell Keith-Magee
On Fri, Jul 18, 2014 at 4:45 AM, Neto  wrote:

> Using 'locals ()' would slow page loading? What is better?
>

Using locals() as template context might give you a *slight* slowdown in
template rendering (since you'll have lots of context variables that you
won't be using). However, that effect would be negligible.

There's a much better reason that you shouldn't use locals() as a template
context - it can lead to unexpected side effects and hard-to-debug problems.

If you use locals() as a template context, *every* variable in your local
context - including ones that you've included for counting or other
temporary storage - are used as part of your template rendering. So - lets
say you develop a template that checks {% if foo %}. Intially; your view
doesn't assign anything to foo, so the block doesn't execute. But then, six
months later, you start using a temporary variable foo in your view - all
of a sudden, the template will start rendering the block. You haven't
changed anything in your template - you're just using a temporary variable
that you weren't using before. You didn't *intend* to make a change to your
template; the rendering of the template has changed as result of something
unrelated to the template design.

The Zen of Python says "explicit is better than implicit"; this is a
perfect example of just that. If you're explicit about what you want to
render, and what you pass to a context, this sort of bug will never happen.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJxq84-k_UJqHifWbgwaXrbymL9Dg43H5cM3A3R%2B_XsfiJTzew%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Should I use 'locals()' or create a dictionary with the template variables? What is better?

2014-07-17 Thread Neto
Using 'locals ()' would slow page loading? What is better?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/82e5ca4e-19af-403b-b64c-615b781532c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Template variables in translation blocks

2013-08-26 Thread Some Developer

On 24/08/13 14:56, Ariel Calzada wrote:

you have to append strings first

http://stackoverflow.com/questions/4386168/how-to-concatenate-strings-in-django-templates

and then call trans



2013/8/24 Some Developer mailto:someukdevelo...@gmail.com>>

I have a title and a header block which normally contain static text
but for some pages I need to display some dynamic information
contained in a template variable.

So I might have the template variable: {{ app.name  }}

and the block code:

{% block title %}
 {% trans "{{ app.name  }} Information" %}
{% endblock %}

Obviously this doesn't work. What is the correct way to solve this
issue? I've done it in the past but I can't for the life of me
remember how.


This was actually significantly easier than described above. The 
following works just fine and is much simpler than having to deal with 
string concatenation in templates.


{% blocktrans with app_name=app.name %}
Edit {{ app_name }}
{% endblocktrans %}

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Template variables in translation blocks

2013-08-24 Thread Some Developer

On 24/08/13 14:56, Ariel Calzada wrote:

you have to append strings first

http://stackoverflow.com/questions/4386168/how-to-concatenate-strings-in-django-templates

and then call trans



2013/8/24 Some Developer mailto:someukdevelo...@gmail.com>>

I have a title and a header block which normally contain static text
but for some pages I need to display some dynamic information
contained in a template variable.

So I might have the template variable: {{ app.name  }}

and the block code:

{% block title %}
 {% trans "{{ app.name  }} Information" %}
{% endblock %}

Obviously this doesn't work. What is the correct way to solve this
issue? I've done it in the past but I can't for the life of me
remember how.



Aha. Thank you! I knew there was something I was missing.

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Template variables in translation blocks

2013-08-24 Thread Ariel Calzada
you have to append strings first

http://stackoverflow.com/questions/4386168/how-to-concatenate-strings-in-django-templates

and then call trans



2013/8/24 Some Developer 

> I have a title and a header block which normally contain static text but
> for some pages I need to display some dynamic information contained in a
> template variable.
>
> So I might have the template variable: {{ app.name }}
>
> and the block code:
>
> {% block title %}
> {% trans "{{ app.name }} Information" %}
> {% endblock %}
>
> Obviously this doesn't work. What is the correct way to solve this issue?
> I've done it in the past but I can't for the life of me remember how.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to 
> django-users+unsubscribe@**googlegroups.com
> .
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at 
> http://groups.google.com/**group/django-users
> .
> For more options, visit 
> https://groups.google.com/**groups/opt_out
> .
>



-- 
Ariel Calzada
Homepage: http://www.000paradox000.com
Blog: http://blog.000paradox000.com

"If I had asked people what they wanted, they would have said faster
horses."

 -- Henry Ford

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Template variables in translation blocks

2013-08-24 Thread Some Developer
I have a title and a header block which normally contain static text but 
for some pages I need to display some dynamic information contained in a 
template variable.


So I might have the template variable: {{ app.name }}

and the block code:

{% block title %}
{% trans "{{ app.name }} Information" %}
{% endblock %}

Obviously this doesn't work. What is the correct way to solve this 
issue? I've done it in the past but I can't for the life of me remember how.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Passing template variables within static template

2012-10-05 Thread Zoran Hranj
Doh!

Thank you, sir!

On Thursday, October 4, 2012 5:17:59 PM UTC+2, Laxmikant Gurnalkar wrote:
>
> Try,
>  
> cheers
> L
> On Thu, Oct 4, 2012 at 8:27 PM, Zoran Hranj 
> > wrote:
>
>> Hi guys,
>>
>> basicly I want to do the following:
>>
>> 
>>
>> But the "{{ item.url }}" part does not get evaluated. I understand why it 
>> is not evaualted, but I want to know if there is a filter or something to 
>> make it work like I want to (quick glance on the filter list didnt give me 
>> any ideas).
>>  
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/django-users/-/G8nMOFvfW9cJ.
>> To post to this group, send email to django...@googlegroups.com
>> .
>> To unsubscribe from this group, send email to 
>> django-users...@googlegroups.com .
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>
>
> -- 
> * 
>
>  GlxGuru
>
> *
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/_a4HiU6VssoJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Passing template variables within static template

2012-10-04 Thread Zoran Hranj
Hi guys,

basicly I want to do the following:



But the "{{ item.url }}" part does not get evaluated. I understand why it 
is not evaualted, but I want to know if there is a filter or something to 
make it work like I want to (quick glance on the filter list didnt give me 
any ideas).

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/G8nMOFvfW9cJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Parse a javascript file having django template variables

2011-11-25 Thread IanKRolfe
Or you can render the js file as if it was a template.
Put the javascript in a template directory.

In the main HTML, change the tag to something like 

Re: Parse a javascript file having django template variables

2011-11-25 Thread Alessandro Candini

On 11/25/2011 03:06 PM, Tom Evans wrote:

On Fri, Nov 25, 2011 at 11:25 AM, Alessandro Candini  wrote:

Hi everybody.

I have an application with the following structure:

STO
├── __init__.py
├── jsonopenlayers
│ ├── __init__.py
│ ├── models.py
│ ├── static
│ │ ├── css
│ │ │ └── STO.css
│ │ └── js
│ │ └── renderMaps.js
│ ├── tests.py
│ └── views.py
├── manage.py
├── settings.py
├── templates
│ └── jsonopenlayers
│ └── index.html
└── urls.py

Static files are found, but I have the problem that inside renderMaps.js I
have some Django template tag to be interpreted.
How can I tell Django to parse also that, in addition to my index.html?

Thanks in advance.


The only way you can manage this is to deliver that file not as a
static file, but as something that has been passed through the
template engine. The template engine can generate any content, be sure
to pass the correct content type ('text/javascript') when you return
the response, and use the cache_page decorator to avoid re-doing it
lots of times.

That is a pain, so a common work-around I use is to re-work it so that
the url to use is something that is passed to the function, and then
insert it into the appropriate templates.

Cheers

Tom

Thank you, but I adopted the method indicated here: 
http://stackoverflow.com/questions/6008908/use-django-template-tags-in-jquery-javascript


I have deleted renderMaps.js and created a new template named 
index_renderMaps.html, containing only a script tag with inside the 
javascript previously into renderMaps.js.
After that I have simply used an {% include "index_renderMaps.html" %} 
into index.html template.


--
Alessandro Candini
MEEO S.r.l.
Via Saragat 9
I-44122 Ferrara, Italy
Tel: +39 0532 1861501
Fax: +39 0532 1861637
http://www.meeo.it


"ATTENZIONE:le informazioni contenute in questo messaggio sono
da considerarsi confidenziali ed il loro utilizzo è riservato unicamente
al destinatario sopra indicato. Chi dovesse ricevere questo messaggio
per errore è tenuto ad informare il mittente ed a rimuoverlo
definitivamente da ogni supporto elettronico o cartaceo."

"WARNING:This message contains confidential and/or proprietary
information which may be subject to privilege or immunity and which
is intended for use of its addressee only. Should you receive this
message in error, you are kindly requested to inform the sender and
to definitively remove it from any paper or electronic format."

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Parse a javascript file having django template variables

2011-11-25 Thread Tom Evans
On Fri, Nov 25, 2011 at 11:25 AM, Alessandro Candini  wrote:
> Hi everybody.
>
> I have an application with the following structure:
>
> STO
> ├── __init__.py
> ├── jsonopenlayers
> │ ├── __init__.py
> │ ├── models.py
> │ ├── static
> │ │ ├── css
> │ │ │ └── STO.css
> │ │ └── js
> │ │ └── renderMaps.js
> │ ├── tests.py
> │ └── views.py
> ├── manage.py
> ├── settings.py
> ├── templates
> │ └── jsonopenlayers
> │ └── index.html
> └── urls.py
>
> Static files are found, but I have the problem that inside renderMaps.js I
> have some Django template tag to be interpreted.
> How can I tell Django to parse also that, in addition to my index.html?
>
> Thanks in advance.
>

The only way you can manage this is to deliver that file not as a
static file, but as something that has been passed through the
template engine. The template engine can generate any content, be sure
to pass the correct content type ('text/javascript') when you return
the response, and use the cache_page decorator to avoid re-doing it
lots of times.

That is a pain, so a common work-around I use is to re-work it so that
the url to use is something that is passed to the function, and then
insert it into the appropriate templates.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Parse a javascript file having django template variables

2011-11-25 Thread Alessandro Candini

Hi everybody.

I have an application with the following structure:

STO
├── __init__.py
├── jsonopenlayers
│ ├── __init__.py
│ ├── models.py
│ ├── static
│ │ ├── css
│ │ │ └── STO.css
│ │ └── js
│ │ └── renderMaps.js
│ ├── tests.py
│ └── views.py
├── manage.py
├── settings.py
├── templates
│ └── jsonopenlayers
│ └── index.html
└── urls.py

Static files are found, but I have the problem that inside renderMaps.js 
I have some Django template tag to be interpreted.

How can I tell Django to parse also that, in addition to my index.html?

Thanks in advance.

--
Alessandro Candini
MEEO S.r.l.
Via Saragat 9
I-44122 Ferrara, Italy
Tel: +39 0532 1861501
Fax: +39 0532 1861637
http://www.meeo.it


"ATTENZIONE:le informazioni contenute in questo messaggio sono
da considerarsi confidenziali ed il loro utilizzo è riservato unicamente
al destinatario sopra indicato. Chi dovesse ricevere questo messaggio
per errore è tenuto ad informare il mittente ed a rimuoverlo
definitivamente da ogni supporto elettronico o cartaceo."

"WARNING:This message contains confidential and/or proprietary
information which may be subject to privilege or immunity and which
is intended for use of its addressee only. Should you receive this
message in error, you are kindly requested to inform the sender and
to definitively remove it from any paper or electronic format."

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



FormPreview and template variables

2011-10-27 Thread NewsNerd
I'm a Django noob and fear the answer to my question is fairly obvious, but 
hoping someone can help.

I'm building an app that includes the same form on every page, with the content 
surrounding the form and the model instance to which the form data is tied 
dependent on a value passed in the URL. Works fine using the standard Form 
class and (URL, 'template.html', myapp.view) in URLconf, like so:

  url(r'^listings/(?P\d+)/submit$', 'myapp.views.lister'),

With FormPreview, however, instead of calling the view in the URLconf, you're 
calling the subclass with the view functionality baked in. 

 url(r'^listings/(?P\d+)/submit$', PickFormPreview(PickForm)),

>From what I can gather from the docs, FormPreview uses parse_params to pass 
>values captured in the URL to state.self, which I believe is a dictionary. 
>Unfortunately given my level of experience, I can't figure out from this 
>barebones understanding how to customize my FormPreview subclass how to pass 
>the listing_id captured in the URL to a template variable in my form.html 
>template called by FormPreview. Do I somehow need to override parse_params? Or 
>somehow pass state.listing_id? Or am I missing it entirely?

Any help much appreciated!
  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/HD4mEMFcfb0J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Parse template variables in custom tag

2011-03-22 Thread Turner
I think I've solved the issue. Rather than create a Variable object, I
called parser.compile_filters(value) in the parsing function for my
tag. That seems to have done the trick, and seems to internally
resolve with a Variable object all the same.



On Mar 21, 9:05 pm, Turner  wrote:
> On Mar 20, 11:15 pm, Daniel Roseman  wrote:
>
> > On Sunday, March 20, 2011 9:57:04 PM UTC, Turner wrote:
>
> > > I'm working on a custom tag to which I would like to be able to pass
> > > template variables and filters. I found
> > > Variable(value).resolve(context) in the Django source. I
> > > have a couple of questions:
>
> > > You don't need to look at the code, this is explicitly documented:
>
> >http://docs.djangoproject.com/en/1.2/howto/custom-template-tags/#pass...
>
> Ah, I somehow missed that in my searching.
>
>
>
> > > 1) Is it safe to use Variable()? That is, is it part of
> > > the public API? Not having visibility modifiers makes it a bit
> > > difficult to tell.
>
> > Yes, since it is documented.
>
> > > 2) Variable.resolve() works fine for, well, resolving a variable, but
> > > doesn't work with filters. That is, if I pass to my tag
> > > some.context.variable|some_filter, the tag will throw up
> > > on the last bit, saying that it can't find an attribute/key/method
> > > called  "variable|some_filter". Is there an easy way I can have my tag
> > > apply any filters to the value passed in?
>
> > AFAIK that should just work. The `with` tag, for example, works fine with
> > arguments that include filters.
>
> Here's the exception I get when I try a variable with filters:
>
> Caught VariableDoesNotExist while rendering: Failed lookup for key
> [path|split_path]
>
> It's raised on the following template call:
>
> {% my_tag list=form.instance.path|split_path %}
>
> (split_path is, obviously, a custom filter)
>
> In the code for my tag I have the following
>
> Variable(value).resolve(context)
>
> (where value is "form.instance.path|split_path")
>
> I'm using Django version 1.3 alpha 1, if that makes a difference.> --
> > DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Parse template variables in custom tag

2011-03-21 Thread Turner


On Mar 20, 11:15 pm, Daniel Roseman  wrote:
> On Sunday, March 20, 2011 9:57:04 PM UTC, Turner wrote:
>
> > I'm working on a custom tag to which I would like to be able to pass
> > template variables and filters. I found
> > Variable(value).resolve(context) in the Django source. I
> > have a couple of questions:
>
> > You don't need to look at the code, this is explicitly documented:
>
> http://docs.djangoproject.com/en/1.2/howto/custom-template-tags/#pass...

Ah, I somehow missed that in my searching.

>
> > 1) Is it safe to use Variable()? That is, is it part of
> > the public API? Not having visibility modifiers makes it a bit
> > difficult to tell.
>
> Yes, since it is documented.
>
> > 2) Variable.resolve() works fine for, well, resolving a variable, but
> > doesn't work with filters. That is, if I pass to my tag
> > some.context.variable|some_filter, the tag will throw up
> > on the last bit, saying that it can't find an attribute/key/method
> > called  "variable|some_filter". Is there an easy way I can have my tag
> > apply any filters to the value passed in?
>
> AFAIK that should just work. The `with` tag, for example, works fine with
> arguments that include filters.

Here's the exception I get when I try a variable with filters:

Caught VariableDoesNotExist while rendering: Failed lookup for key
[path|split_path]

It's raised on the following template call:

{% my_tag list=form.instance.path|split_path %}

(split_path is, obviously, a custom filter)

In the code for my tag I have the following

Variable(value).resolve(context)

(where value is "form.instance.path|split_path")

I'm using Django version 1.3 alpha 1, if that makes a difference.

> --
> DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Parse template variables in custom tag

2011-03-20 Thread Daniel Roseman
On Sunday, March 20, 2011 9:57:04 PM UTC, Turner wrote:
>
> I'm working on a custom tag to which I would like to be able to pass 
> template variables and filters. I found 
> Variable(value).resolve(context) in the Django source. I 
> have a couple of questions: 
>
> You don't need to look at the code, this is explicitly documented:
http://docs.djangoproject.com/en/1.2/howto/custom-template-tags/#passing-template-variables-to-the-tag
 

> 1) Is it safe to use Variable()? That is, is it part of 
> the public API? Not having visibility modifiers makes it a bit 
> difficult to tell. 
>

Yes, since it is documented. 

 

> 2) Variable.resolve() works fine for, well, resolving a variable, but 
> doesn't work with filters. That is, if I pass to my tag 
> some.context.variable|some_filter, the tag will throw up 
> on the last bit, saying that it can't find an attribute/key/method 
> called  "variable|some_filter". Is there an easy way I can have my tag 
> apply any filters to the value passed in?


AFAIK that should just work. The `with` tag, for example, works fine with 
arguments that include filters. 
--
DR. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Parse template variables in custom tag

2011-03-20 Thread Turner
I'm working on a custom tag to which I would like to be able to pass
template variables and filters. I found
Variable(value).resolve(context) in the Django source. I
have a couple of questions:

1) Is it safe to use Variable()? That is, is it part of
the public API? Not having visibility modifiers makes it a bit
difficult to tell.

2) Variable.resolve() works fine for, well, resolving a variable, but
doesn't work with filters. That is, if I pass to my tag
some.context.variable|some_filter, the tag will throw up
on the last bit, saying that it can't find an attribute/key/method
called  "variable|some_filter". Is there an easy way I can have my tag
apply any filters to the value passed in?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



model instances, schema and template variables

2010-07-12 Thread Alex
Hi,

Just want to know if this is the correct understanding of how model
instances are passed to templates.

If I load a model instance object into a template - is it the case
that I also implicitly load in any instance objects it is related
through foreign key fields? It seems that these, and in turn, any
foreign keys those objects have, are also loaded.

eg
return render_to_response("startpage.html", {
'A': instance1,
}, context_instance=RequestContext(request))

so in the template I can do things like:

{{ A.fk_field.name }}
{{ A.fk_field.another_fk_field.name}}

Is this correct - and how should it be controlled - supposing I really
do only want 'instance1' without FK following.

Is it also the case if I want access to an instance's reverse
relationship objects I have to explicitly load those into the template
seperately?
eg
return render_to_response("startpage.html", {
'A': instance1,
'BList': instance1.other_set.all(),
}, context_instance=RequestContext(request))

so in the template I can do

{% for B in BList %}
do something with B
{% endfor %}

Sorry if this is answered elsewhere but just couldn't find it!

Thanks
 Alex

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django template variables

2010-07-11 Thread Syed Ali Saim
:)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django template variables

2010-07-10 Thread commonzenpython
alright, thanks a lot Syed :P

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django template variables

2010-07-10 Thread Syed Ali Saim
dude I missed 1 important import.

first add this,

-
from django.template import RequestContext


also makesure your template path is set in settings.py

mine looks something like this

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.
"C:/Appframework/evento/evento/templates"
)

so all my html  file reside inside the templates directory, its like
doc-root. it can also have sub directories inside it. it also has to be on
the same level as my setttings.py and manage.py
--
and no you can render as many variables as like this

 variables = RequestContext(request,{ 'paragraph': para ,
'variable2':v2,
 'variable3':v3})
-

hope this solves you problem.




On Sat, Jul 10, 2010 at 1:39 PM, commonzenpython
wrote:

> thanks, unfortunately i keep getting a 404, the templates name is
> 2col.html, its inside ash/templates, the url i have is (r'^paragraph/
> $', 'show_para'),   and the views is
> from django.http import HttpResponse
> from django.shortcuts import render_to_response
>
> def show_para(request):
>para = "I love this project"
>variables = RequestContext(request,{ 'paragraph': para})
>return render_to_response('2col.html',variables)
>
> even if it works i was wondering if i would have to create a new
> function for every variable,
> thanks
>
> --
>  You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Syed Ali Saim
Project Manager
Softech Worldwide LLC

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django template variables

2010-07-10 Thread commonzenpython
thanks, unfortunately i keep getting a 404, the templates name is
2col.html, its inside ash/templates, the url i have is (r'^paragraph/
$', 'show_para'),   and the views is
from django.http import HttpResponse
from django.shortcuts import render_to_response

def show_para(request):
para = "I love this project"
variables = RequestContext(request,{ 'paragraph': para})
return render_to_response('2col.html',variables)

even if it works i was wondering if i would have to create a new
function for every variable,
thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django template variables

2010-07-10 Thread Syed Ali Saim
you can use django render_to_response which by far the most common and
preferred way, i found as newbie my self.

here is an example: (roughly but will give you an idea)

---
Now following this is an extremly crude tut by myself, for a superb one try
http://docs.djangoproject.com/en/1.2/intro/tutorial01/#intro-tutorial01
--


1: you need to create and html file in which you will write your markup
something, like and store it somewhere in your template directory lets
assume you call it paragraph.html


.
 {{paragraph}} 



2: Next edit urls.py and add a pettern something similar this is important
cause this is how django will know what url your looking for and call the
appropriate function, the function you will write in step three. open
urls.py and add

 # this is how django serves a function to prepare a view for a url. So here
is what you tell django to do when some one request a url say
# "http://yourserver/paragraph/";

urlpatterns = patterns('',
(r'^paragraph/$', show_para) ,)


3: You will write your business logic in views.py, in form of function

from django.shortcuts import render_to_response

def show_para(request)
 para = " I love this project"

variables = RequestContext(request,{ 'paragraph': para}) # telling django to
store the value in para , in the template variable paragraph

return render_to_response('paragraph.html',variables) # here is what the
user is served an html, with values you placed in it.

--




On Sat, Jul 10, 2010 at 12:01 PM, commonzenpython  wrote:

> hey guys, im trying to create a template that uses variables like
> {{ paragraph }} , but i cannot find how to get django to render
> the paragraph into the variable, i know i have to create a .py file
> that uses django's render class to render the paragraph but how can i
> connect the html file to the .py file so that it renders it
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Syed Ali Saim
Project Manager
Softech Worldwide LLC

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



django template variables

2010-07-10 Thread commonzenpython
hey guys, im trying to create a template that uses variables like
{{ paragraph }} , but i cannot find how to get django to render
the paragraph into the variable, i know i have to create a .py file
that uses django's render class to render the paragraph but how can i
connect the html file to the .py file so that it renders it

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Changing template variables

2010-03-05 Thread Kevin Renskers
For those interested:

In my base template I've added this:

{% load custom_tags %}
{% if form %}
{% formerrors request form %}
{% endif %}

In my custom_tags template tags library:

@register.simple_tag
def formerrors(request, form):
for field, errors in form.errors.items():
for error in errors:
if field == '__all__':
messages.error(request, error)
else:
messages.error(request, field+': '+error)

return ''


Works perfectly for me: now all form errors are shown in exactly the
same way as all other messages in my application.

Cheers,
Kevin


On Mar 4, 4:33 pm, Kevin Renskers  wrote:
> I'll explain a bit more what precisely it is what I want to do: Django
> 1.2 comes with a new messages framework that allows for each message
> to have a different "level" (succes, error, warning, etc). I want to
> see if a form has errors, and if so, make a message for each error so
> all my notices and errors are displayed in the same way in my
> application.
>
> But I think I just came up with a solution: make a new template tag in
> my base template, always give it the form variable (whether it exists
> or not), and from there create the new messages.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Changing template variables

2010-03-04 Thread Kevin Renskers
I'll explain a bit more what precisely it is what I want to do: Django
1.2 comes with a new messages framework that allows for each message
to have a different "level" (succes, error, warning, etc). I want to
see if a form has errors, and if so, make a message for each error so
all my notices and errors are displayed in the same way in my
application.

But I think I just came up with a solution: make a new template tag in
my base template, always give it the form variable (whether it exists
or not), and from there create the new messages.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Changing template variables

2010-03-04 Thread Bill Freeman
Write your new view so that it can be used generically.

On Thu, Mar 4, 2010 at 10:22 AM, Kevin Renskers  wrote:
> Well yes, but I do not want to change all of my views. I want a
> generic solution to change template variables before they get
> rendered.
>
>
> On Mar 4, 4:14 pm, Bill Freeman  wrote:
>> Write your own view instead of using direct_to_template.
>>
>>
>>
>> On Thu, Mar 4, 2010 at 10:06 AM, Kevin Renskers  wrote:
>> > Hi,
>>
>> > I am wondering if it is possible to change template variables before
>> > they get rendered in a template.
>>
>> > For example, I use something like this in my template:
>> > return direct_to_template(request, template='index.html',
>> > extra_context={'form':form})
>>
>> > I would like to extend this form variable before the index.html
>> > template gets rendered.
>>
>> > My first though was making a template context processor, but I can't
>> > seem to be able to access template variables from it. My next thought
>> > was creating a piece of middleware with a process_response function,
>> > but also from this function it seems impossible to access the template
>> > variables.
>>
>> > Anyone got an idea on how to do this?
>>
>> > Thanks in advance,
>> > Kevin
>>
>> > --
>> > You received this message because you are subscribed to the Google Groups 
>> > "Django users" group.
>> > To post to this group, send email to django-us...@googlegroups.com.
>> > To unsubscribe from this group, send email to 
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group 
>> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Changing template variables

2010-03-04 Thread Kevin Renskers
Well yes, but I do not want to change all of my views. I want a
generic solution to change template variables before they get
rendered.


On Mar 4, 4:14 pm, Bill Freeman  wrote:
> Write your own view instead of using direct_to_template.
>
>
>
> On Thu, Mar 4, 2010 at 10:06 AM, Kevin Renskers  wrote:
> > Hi,
>
> > I am wondering if it is possible to change template variables before
> > they get rendered in a template.
>
> > For example, I use something like this in my template:
> > return direct_to_template(request, template='index.html',
> > extra_context={'form':form})
>
> > I would like to extend this form variable before the index.html
> > template gets rendered.
>
> > My first though was making a template context processor, but I can't
> > seem to be able to access template variables from it. My next thought
> > was creating a piece of middleware with a process_response function,
> > but also from this function it seems impossible to access the template
> > variables.
>
> > Anyone got an idea on how to do this?
>
> > Thanks in advance,
> > Kevin
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Changing template variables

2010-03-04 Thread Bill Freeman
Write your own view instead of using direct_to_template.

On Thu, Mar 4, 2010 at 10:06 AM, Kevin Renskers  wrote:
> Hi,
>
> I am wondering if it is possible to change template variables before
> they get rendered in a template.
>
> For example, I use something like this in my template:
> return direct_to_template(request, template='index.html',
> extra_context={'form':form})
>
> I would like to extend this form variable before the index.html
> template gets rendered.
>
> My first though was making a template context processor, but I can't
> seem to be able to access template variables from it. My next thought
> was creating a piece of middleware with a process_response function,
> but also from this function it seems impossible to access the template
> variables.
>
> Anyone got an idea on how to do this?
>
> Thanks in advance,
> Kevin
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Changing template variables

2010-03-04 Thread Kevin Renskers
Hi,

I am wondering if it is possible to change template variables before
they get rendered in a template.

For example, I use something like this in my template:
return direct_to_template(request, template='index.html',
extra_context={'form':form})

I would like to extend this form variable before the index.html
template gets rendered.

My first though was making a template context processor, but I can't
seem to be able to access template variables from it. My next thought
was creating a piece of middleware with a process_response function,
but also from this function it seems impossible to access the template
variables.

Anyone got an idea on how to do this?

Thanks in advance,
Kevin

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Template variables and tags confusion... (regarding concatenation)

2009-11-21 Thread chefsmart
Exactly. Thanks.

On Nov 21, 4:45 pm, Tim Chase  wrote:
> > When I do  in a template I get  > id="item_1"> in the rendered html as expected.
>
> > Now I want to do {% cycle '' ' > class="odd" id="item_{{ product.id }}">' %}, but the desired
> > concatenation does not happen.
>
> > How do I achieve what I want?
>
> sounds like you want something like
>
>         id="item_{{ product.id }}">
>
> -tim

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.




Re: Template variables and tags confusion... (regarding concatenation)

2009-11-21 Thread Tim Chase
> When I do  in a template I get  id="item_1"> in the rendered html as expected.
> 
> Now I want to do {% cycle '' ' class="odd" id="item_{{ product.id }}">' %}, but the desired
> concatenation does not happen.
> 
> How do I achieve what I want?


sounds like you want something like

   

-tim




--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.




Template variables and tags confusion... (regarding concatenation)

2009-11-21 Thread chefsmart
Hi,

When I do  in a template I get  in the rendered html as expected.

Now I want to do {% cycle '' '' %}, but the desired
concatenation does not happen.

How do I achieve what I want?

Regards.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.




Why can't template variables be used as filters?

2009-06-26 Thread ssadler

This is a general question. I think it would be useful to be able to
use template variables as filters. Consider the following: I need to
display dates according to a user's timezone. My options are to create
these translated dates in the view code (assign them to model
instances or create a new data structure, both of which take a few
lines of code, and neither of which I really like), or have a general
datetime translator template filter which takes the timezone as an
argument. IE:

{{ object.date|tz_translate:request.timezone|date:"d/m/y H:i" }}

However, if I could use a template variable as a filter, I think it
would be cleaner and easier for template authors too:

c = RequestContext(request, {
'objects': SomeModel.objects.all(),
'tz_translate': functools.partial(tz_translate, request.timezone),
})

Then in the template:

{{ objects.date|tz_translate|date:"d/m/y H:i" }}

It's easier no?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: jquery ajax form problem--Can't render template variables

2009-06-10 Thread Malcolm MacKinnon
Thanks Alex. I'll give it a try. I appreciate your comments.

On Wed, Jun 10, 2009 at 5:49 AM, Alex Robbins  wrote:

>
> I haven't used that form plugin before, but from the documentation it
> looks like the problem is this line:
> target:"#new",
> http://malsup.com/jquery/form/#options-object
> You are asking jQuery to jam the whole response in, just like you are
> seeing. What happens if you take that line out? It looks like it will
> just call your success callback. Watch out though, I think the success
> callback happens whenever you get a 200 response from the server. That
> will happen even if your form is bad. (There will be a 200 response
> with errors in it.) You need to check if the response is good or bad
> based on the text in the response, which would get passed to the
> success callback as response_text)
>
> Anyway, I haven't actually used this library but that is how the
> jquery ajax callbacks work.
>
> Hope that helps,
> Alex
>
> On Jun 9, 6:01 pm, Mac  wrote:
> > I'm new to programming and can't figure out how to properly render the
> > {{comment}} and {{username}} variables in the  element
> > below using jquery and the ajax form plugin. Everything posts to the
> > database just as it should. However, I want to show what gets posted
> > in the template after submission. What happens is the entire html page
> > gets inserted in the  element. The images, everything,
> > gets duplicated as the response_text is inserted. Note that the
> > following code has a lot of simple test scripts I'm attempting to use.
> > My template looks like this:
> > (I'm referencing a javascript file, global.js in the template, which
> > is included below it):
> >
> > {% extends "base.html" %}
> > {%block content %}
> > 
> > 

Re: jquery ajax form problem--Can't render template variables

2009-06-10 Thread Alex Robbins

I haven't used that form plugin before, but from the documentation it
looks like the problem is this line:
target:"#new",
http://malsup.com/jquery/form/#options-object
You are asking jQuery to jam the whole response in, just like you are
seeing. What happens if you take that line out? It looks like it will
just call your success callback. Watch out though, I think the success
callback happens whenever you get a 200 response from the server. That
will happen even if your form is bad. (There will be a 200 response
with errors in it.) You need to check if the response is good or bad
based on the text in the response, which would get passed to the
success callback as response_text)

Anyway, I haven't actually used this library but that is how the
jquery ajax callbacks work.

Hope that helps,
Alex

On Jun 9, 6:01 pm, Mac  wrote:
> I'm new to programming and can't figure out how to properly render the
> {{comment}} and {{username}} variables in the  element
> below using jquery and the ajax form plugin. Everything posts to the
> database just as it should. However, I want to show what gets posted
> in the template after submission. What happens is the entire html page
> gets inserted in the  element. The images, everything,
> gets duplicated as the response_text is inserted. Note that the
> following code has a lot of simple test scripts I'm attempting to use.
> My template looks like this:
> (I'm referencing a javascript file, global.js in the template, which
> is included below it):
>
> {% extends "base.html" %}
> {%block content %}
> 
> 

jquery ajax form problem--Can't render template variables

2009-06-09 Thread Mac

I'm new to programming and can't figure out how to properly render the
{{comment}} and {{username}} variables in the  element
below using jquery and the ajax form plugin. Everything posts to the
database just as it should. However, I want to show what gets posted
in the template after submission. What happens is the entire html page
gets inserted in the  element. The images, everything,
gets duplicated as the response_text is inserted. Note that the
following code has a lot of simple test scripts I'm attempting to use.
My template looks like this:
(I'm referencing a javascript file, global.js in the template, which
is included below it):

{% extends "base.html" %}
{%block content %}



 Welcome to Site
{% include "form.html" %}



This will fade out
Here is the camo image

Users and comments:


{{comment}}
{{username}}



{% if error %}
Errors:
{{error}}
{% endif %}

{% endblock%}



Here is global.js

$(document).ready(function(){
$("div.htm").text("The DOM is now loaded and can be
manipulated.");

 $(":header").css({ background:'#CCC', color:'green' });
  $("img").css({ width:'25%' });
  $("p").bind("click", function(e){
  var str = "( " + e.pageX + ", " + e.pageY + " )";
  $("div.htm").text("Click happened! " + str);
});
$("form.theform").ajaxForm({
clearform: true,
target:"#new",
success: function(response_text, status_text) {
var $inp=$("input.com").val();
var $inpa=$("textarea.comms").val();
$("input.news").val($inp);
$("Hello" + " " + $inp + " " + $inpa + "").appendTo("div.htm");
$("p.hide").hide();

$("input.com").val("");
$("textarea.comms").val("");
alert("ajx working");
alert(response_text);
$("Thanks for your sporthill order!").appendTo("p.inp");
$("div.shw").show("slow");
$('p.inp').fadeOut("slow");
$('#hide').hide();

}
});

 });




view is:
def ajx_form(request):


if form.is_valid:
if request.is_ajax:
name = request.POST.get('name', '')
password = request.POST.get('password', '')
comments=request.POST.get('comment', '')
u=Users.objects.create(user=name,  comment=comments)

return render_to_response('my_ajx.html',
{'username':name,  'comment': comments, 'request':request, },
context_instance=RequestContext(request))
return render_to_response('my_ajx.html', {'error':'You"ve got
errors',   },  context_instance=RequestContext(request))
return render_to_response('my_ajx.html', {'error':'You"ve got
errors',   },  context_instance=RequestContext(request))

Please let me know if you have a solution or any ideas. Thanks!!

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: "-" in template variables

2009-05-10 Thread Danne

Yeah, that could have been a greate solution :) The problem is that
there is a huge amount of key-value sets to replace, and i don't want
to replace "-" in the blog posts (Tumblr is a blogging service). That
would result in a pretty complex regular expression.

What I did instead to solve this was to make a template filter.
Syntax for using this is {{ post|tumblr_var:"regular-title" }}, and it
will print post["regulat-title"].

The code in the filter is simple:

from django import template

register = template.Library()

def tumblr_var(value, key):
return value[key]

register.filter("tumblr_var", tumblr_var)

Thanks for your comments :)

On May 10, 12:17 pm, Daniel Roseman 
wrote:
> On May 10, 1:58 am, Danne  wrote:
>
> > I'm using the Tumblr (http://www.tumblr.com) REST Api, and keys in
> > returned json contains the character "-", like "post": {"regular-
> > title": "asdf" .}. I'm having trouble printing this in the django
> > templates since regular-title is an invalid variable name. I've tried
> > stuff like: post["regular-title"], post[regular-title], post.regular-
> > title and so on, and searched around the docs and mailing lists, but
> > haven't found any answers.
>
> > Is there a way to print template variables with "-" in their names?
>
> Django templates don't use brackets in dictionary lookups, so
> post.regular-title would be the correct syntax.
>
> How are you getting the data from Tumblr into the template? If the API
> is returning JSON, at some point (before you parse it) it's just a
> string, so you could do x.replace('regular-title', 'regular_title') to
> convert the keys into valid Python variables, if that is indeed the
> cause of your problem.
>
> It would probably help if you posted your view code.
> --
> DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: "-" in template variables

2009-05-10 Thread Daniel Roseman

On May 10, 1:58 am, Danne  wrote:
> I'm using the Tumblr (http://www.tumblr.com) REST Api, and keys in
> returned json contains the character "-", like "post": {"regular-
> title": "asdf" .}. I'm having trouble printing this in the django
> templates since regular-title is an invalid variable name. I've tried
> stuff like: post["regular-title"], post[regular-title], post.regular-
> title and so on, and searched around the docs and mailing lists, but
> haven't found any answers.
>
> Is there a way to print template variables with "-" in their names?

Django templates don't use brackets in dictionary lookups, so
post.regular-title would be the correct syntax.

How are you getting the data from Tumblr into the template? If the API
is returning JSON, at some point (before you parse it) it's just a
string, so you could do x.replace('regular-title', 'regular_title') to
convert the keys into valid Python variables, if that is indeed the
cause of your problem.

It would probably help if you posted your view code.
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: "-" in template variables

2009-05-10 Thread Dougal Matthews
>From the docs;
"Variable names must consist of any letter (A-Z), any digit (0-9), an
underscore or a dot."

http://docs.djangoproject.com/en/dev/ref/templates/api/#rendering-a-context

I suppose you could write a template tag to handle it or something. Not
sure.

Dougal


---
Dougal Matthews - @d0ugal
http://www.dougalmatthews.com/



2009/5/10 Danne 

>
> I'm using the Tumblr (http://www.tumblr.com) REST Api, and keys in
> returned json contains the character "-", like "post": {"regular-
> title": "asdf" .}. I'm having trouble printing this in the django
> templates since regular-title is an invalid variable name. I've tried
> stuff like: post["regular-title"], post[regular-title], post.regular-
> title and so on, and searched around the docs and mailing lists, but
> haven't found any answers.
>
> Is there a way to print template variables with "-" in their names?
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



"-" in template variables

2009-05-09 Thread Danne

I'm using the Tumblr (http://www.tumblr.com) REST Api, and keys in
returned json contains the character "-", like "post": {"regular-
title": "asdf" .}. I'm having trouble printing this in the django
templates since regular-title is an invalid variable name. I've tried
stuff like: post["regular-title"], post[regular-title], post.regular-
title and so on, and searched around the docs and mailing lists, but
haven't found any answers.

Is there a way to print template variables with "-" in their names?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Template Variables as Indexes

2009-04-24 Thread Doug B

Might not be the easiest way, but you could use a custom filter:

def formsbyfield(forms,field):
""" Given a list of similar forms, and a field name,
return a list of formfields, one from each form.
"""
return [form.fields.get(field,'') for form in forms]
register.filter('formsbyfield',formsbyfield)

{% for fieldname in forms.0.fields.keys %}

{% for ff in forms|formsbyfield:fieldname %}
{{ff}}
{% endfor %}

{% endfor %}

Something like that should work, though I haven't tested it.


On Apr 24, 11:18 am, NewSpire  wrote:
> I have a list of forms, all of the same type, where I would like to
> list each form side by side with the fields listed vertically.  The
> root of the problem is that I need to use a template variable as an
> index on another template variable.  Something like this.
>
> 
> {% for field in forms.0 %}
> 
>     {{ field.label }}:
>     {% for form in forms %}
>         {{ form.field.{{ forloop.parentloop.counter0 }} }}
>     {% endfor %}
> 
> {% endfor %}
> 
>
> The outer loop if looping over form.0 to create a row for each set of
> fields and the labels.  The inner loop is providing the list of fields
> for each row.  Does anybody see a way to do something like this?
>
> Thanks!
> Andy
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Template Variables as Indexes

2009-04-24 Thread NewSpire

I have a list of forms, all of the same type, where I would like to
list each form side by side with the fields listed vertically.  The
root of the problem is that I need to use a template variable as an
index on another template variable.  Something like this.


{% for field in forms.0 %}

{{ field.label }}:
{% for form in forms %}
{{ form.field.{{ forloop.parentloop.counter0 }} }}
{% endfor %}

{% endfor %}


The outer loop if looping over form.0 to create a row for each set of
fields and the labels.  The inner loop is providing the list of fields
for each row.  Does anybody see a way to do something like this?

Thanks!
Andy
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Template variables in forms

2008-10-19 Thread Martin

Hello,

i'm trying to use formwizard for my project, but i can't seem to solve
the problem. I have two step formwizard, and i need a variable from
first step to show up in the next.
Second step is a queryset of "available texts" - and there is a
"name" ( lets say {{ name }}) variable in it, that needs to be filled
up according to the name you enter in the first step.

Available texts look something like: Hello, {{ name }} or Wassup,
{{ name }}, etc. Since this available text are selected through
queryset i cannot put a template variable in them.
Does anyone have a solution to this kind of problem?

Thanks in advance,
Martin

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: i18n problem: Some template variables "get stuck" in one language

2008-01-11 Thread Emil

I think I got it! Wrong ordering of middleware - I had the i18n-urls
middleware before some other stuff, which screwed up a lot... It's
working now, and my hair will probably grow back eventually...

//emil

On Jan 11, 12:41 pm, Emil <[EMAIL PROTECTED]> wrote:
> Nope, that doesn't seem to be it - same problem with dummy caching on
> dev server. More likely the culprit is the Advanced Locale From URL
> Middleware I'm using[1]. I inspected the response headers I get, and
> even if the language is set to English on the site, response headers
> always show Content-Language as "sv-se"... Weird thing there is that
> the LANGUAGE_CODE apparently still is correct, because the english
> fields are fetched from the db. I'm using a somewhat crude method for
> getting the correct language content from the db, a switch/case
> template tag (from Jacob Kaplan-Moss, fetched from djangosnippets.org)
> operating on LANGUAGE_CODE and then pulling the correct field from the
> model.
>
> Gaaah. I'm really lost here. Any help would be greatly appreciated. I
> can't seem to find a pattern either in what gets translated correctly
> and when, because it seems to change - also, now, while writing this,
> I noticed that the LANGUAGE_CODE doesn't seem to be correct all the
> time either, but only on some pages... I can't seem to find a pattern
> for when and why this happens.
>
> [1] Link found on the ContributedMiddleware-wiki 
> page:http://www.jondesign.net/articles/2006/jul/02/langue-depuis-url-djang...
>
> //emil
>
> On Jan 11, 11:55 am, Emil <[EMAIL PROTECTED]> wrote:
>
> > Hi Peter,
>
> > thanks for the tip, I'm reading up on the vary_on_headers-decorator
> > right now, I'm gonna see if that clears things up. Just seems weird
> > from my reasoning, and another project I'm working on doesn't have
> > this problem, with nearly excactly the same setup. Oh well, I'll poke
> > around and see what I find.
>
> > Thanks.
>
> > //emil
>
> > On Jan 11, 3:17 am, Peter Rowell <[EMAIL PROTECTED]> wrote:
>
> > > Emil:
>
> > > > Except that on a couple of pages,
> > > > the language seems to get stuck on the translated language after the
> > > > first time I change languages.
>
> > > This smells very much like a caching issue. Do you have any form of
> > > caching enabled? If so, turn it off and see if the problem is
> > > magically fixed.
>
> > > You may need to cache at below-the-page level (ie. component level -
> > > see the cache templatetag) or you may need to add one or more vary-on
> > > variables so that you get different cache values for different
> > > languages (or whatever).
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: i18n problem: Some template variables "get stuck" in one language

2008-01-11 Thread Emil

Nope, that doesn't seem to be it - same problem with dummy caching on
dev server. More likely the culprit is the Advanced Locale From URL
Middleware I'm using[1]. I inspected the response headers I get, and
even if the language is set to English on the site, response headers
always show Content-Language as "sv-se"... Weird thing there is that
the LANGUAGE_CODE apparently still is correct, because the english
fields are fetched from the db. I'm using a somewhat crude method for
getting the correct language content from the db, a switch/case
template tag (from Jacob Kaplan-Moss, fetched from djangosnippets.org)
operating on LANGUAGE_CODE and then pulling the correct field from the
model.

Gaaah. I'm really lost here. Any help would be greatly appreciated. I
can't seem to find a pattern either in what gets translated correctly
and when, because it seems to change - also, now, while writing this,
I noticed that the LANGUAGE_CODE doesn't seem to be correct all the
time either, but only on some pages... I can't seem to find a pattern
for when and why this happens.

[1] Link found on the ContributedMiddleware-wiki page:
http://www.jondesign.net/articles/2006/jul/02/langue-depuis-url-django-url-locale-middleware/

//emil

On Jan 11, 11:55 am, Emil <[EMAIL PROTECTED]> wrote:
> Hi Peter,
>
> thanks for the tip, I'm reading up on the vary_on_headers-decorator
> right now, I'm gonna see if that clears things up. Just seems weird
> from my reasoning, and another project I'm working on doesn't have
> this problem, with nearly excactly the same setup. Oh well, I'll poke
> around and see what I find.
>
> Thanks.
>
> //emil
>
> On Jan 11, 3:17 am, Peter Rowell <[EMAIL PROTECTED]> wrote:
>
> > Emil:
>
> > > Except that on a couple of pages,
> > > the language seems to get stuck on the translated language after the
> > > first time I change languages.
>
> > This smells very much like a caching issue. Do you have any form of
> > caching enabled? If so, turn it off and see if the problem is
> > magically fixed.
>
> > You may need to cache at below-the-page level (ie. component level -
> > see the cache templatetag) or you may need to add one or more vary-on
> > variables so that you get different cache values for different
> > languages (or whatever).
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: i18n problem: Some template variables "get stuck" in one language

2008-01-11 Thread Emil

Hi Peter,

thanks for the tip, I'm reading up on the vary_on_headers-decorator
right now, I'm gonna see if that clears things up. Just seems weird
from my reasoning, and another project I'm working on doesn't have
this problem, with nearly excactly the same setup. Oh well, I'll poke
around and see what I find.

Thanks.

//emil

On Jan 11, 3:17 am, Peter Rowell <[EMAIL PROTECTED]> wrote:
> Emil:
>
> > Except that on a couple of pages,
> > the language seems to get stuck on the translated language after the
> > first time I change languages.
>
> This smells very much like a caching issue. Do you have any form of
> caching enabled? If so, turn it off and see if the problem is
> magically fixed.
>
> You may need to cache at below-the-page level (ie. component level -
> see the cache templatetag) or you may need to add one or more vary-on
> variables so that you get different cache values for different
> languages (or whatever).
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: i18n problem: Some template variables "get stuck" in one language

2008-01-10 Thread Peter Rowell

Emil:

> Except that on a couple of pages,
> the language seems to get stuck on the translated language after the
> first time I change languages.

This smells very much like a caching issue. Do you have any form of
caching enabled? If so, turn it off and see if the problem is
magically fixed.

You may need to cache at below-the-page level (ie. component level -
see the cache templatetag) or you may need to add one or more vary-on
variables so that you get different cache values for different
languages (or whatever).


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



i18n problem: Some template variables "get stuck" in one language

2008-01-10 Thread Emil

Hi folks,

I have a rather peculiar problem. I created translations for my
project, and mostly they work fine. Except that on a couple of pages,
the language seems to get stuck on the translated language after the
first time I change languages.

Example: I visist the site. It's in english (which is the hard-coded
language). I press a link to change to swedish (which is the language
in the .po/.mo-files). It changes to swedish. I visit pages, they're
in swedish. I change back to english. Stuff from the db (from fields
with english text) goes back to english, but variables marked for
translation in templates on certain pages of the site stay in swedish.
Other pages are all in english, as they should.

I haven't got a clue as to why this happens. I tried recompiling the
language files, restarting the server etc. Nothing helps. I even
deleted and redid the translation (an hour of my life I'll never get
back, but I'm glad it's only an hour), recompiled, same problem again.
I have tested this both on my local machine using the dev server and a
testing environment with apache/mod_python, exact same behavior. I'm
using 0.97-PRE.

The only thing in common with the specific pages (2 of them as far as
I can see) where the translation gets stuck that I can think of is
that they use some sort of inclusion tags, one being James Bennet's
Generic Content, the other one a simple one I wrote myself merely
retreiving a list of items.

What gives?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: template variables

2007-10-26 Thread fisher

On Oct 13, 8:09 am, Goon <[EMAIL PROTECTED]> wrote:
> can you use variables in django's templates?
>
> so like {% for x in y %}
>
> and then something like
>
> {% int x =3; x++ %}

Recently I found some handy django snippet which can be usefull for
you.

http://www.djangosnippets.org/snippets/9/

--
Łukasz


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: template variables

2007-10-13 Thread SmileyChris

On Oct 13, 8:35 pm, "Nikola Stjelja" <[EMAIL PROTECTED]> wrote:
> On 10/13/07, Goon <[EMAIL PROTECTED]> wrote:
> > fair enough, I'm not happy that I can't get {{for x in y[1:5]}}
>
> What's the problem. You just send the template 'y':range(1,6). It's very
> simple. I don't think the template system should be changed to do something
> that the programming part of the presentation should do.

Technically, that could be presentation logic. For the common case of
a iterating a set number of times, I wrote 
http://code.djangoproject.com/ticket/5172.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: template variables

2007-10-13 Thread Jeff Forcier

On Oct 13, 3:41 am, Goon <[EMAIL PROTECTED]> wrote:

> Ok, but let's say I have a template like {{for x in y}}, and I would
> like the x's seperated by commas, but I don't want a comma after the
> last one?  or better yet cut off after the first 100 characters with a
> "..."

The key here is that this sort of logic _can_ be accomplished but it's
done by pushing the logic itself into Python code that's related to
the template - filters and tags. There's a lot of built-in ones
(http://www.djangoproject.com/documentation/templates/) and you can
accomplish both of your examples by applying included template filters
like so:

{% for x in y %}
{{ x }}{% if not forloop.last %},{% endif %}
{% endfor %}

Of course, if you're familiar with Python at all you might recall the
string join method; that's here too and is used for exactly this
purpose. So you can actually do:

{{ y|join:"," }}

As for truncating a string, you could use slice as previously noted:

{{ y|slice:":100" }}...

Basically, you just need to become familiar with the tools available -
there's a lot that can be done with them. If you find a need for
something the builtins don't accomplish by themselves or jointly, you
can easily write your own. Again, the idea being to push non-simple or
non-presentation-oriented logic into Python code that *doesn't* live
in the template - separating the layers, as it were. There's plenty of
documentation on it on the site and on blogs and here on the list as
well, if you ever get stuck :)

Regards,
Jeff


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: template variables

2007-10-13 Thread Nikola Stjelja
On 10/13/07, beck917 <[EMAIL PROTECTED]> wrote:
>
> Maybe use the custom template filters is a nice way~
>
> http://www.djangoproject.com/documentation/templates_python/#writing-custom-template-filters
>


Yep. The point is: less programming in html, the better. That's the reason
most experienced php developers adopt one templating system, or the other(or
write their own as I did). I think djangos templating system is nice and
clean, and thats the best compliment a ts can receive in my opinion.

2007/10/13, Nikola Stjelja <[EMAIL PROTECTED]>:
> >
> >
> >
> > On 10/13/07, James Bennett < [EMAIL PROTECTED]> wrote:
> > >
> > >
> > > On 10/13/07, Goon <[EMAIL PROTECTED]> wrote:
> > > > fair enough, I'm not happy that I can't get {{for x in y[1:5]}}
> >
> >
> > What's the problem. You just send the template 'y':range(1,6). It's very
> > simple. I don't think the template system should be changed to do something
> > that the programming part of the presentation should do. It makes
> > unreadeble, unpractical html code which just gets in the way of practiacal
> > web development , it's not mantainance friendly.
> >
> > Perhaps the documentation will make you happy:
> > >
> > > http://www.djangoproject.com/documentation/templates/#slice
> > >
> > > --
> > > "Bureaucrat Conrad, you are technically correct -- the best kind of
> > > correct."
> > >
> > > http://www.1km1kt.net/rpg/Marinci.php
> > >
> > >
> > >
> > >
>
> >
>


-- 
Please visit this site and play my RPG!

http://www.1km1kt.net/rpg/Marinci.php

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: template variables

2007-10-13 Thread beck917
Maybe use the custom template filters is a nice way~

http://www.djangoproject.com/documentation/templates_python/#writing-custom-template-filters


2007/10/13, Nikola Stjelja <[EMAIL PROTECTED]>:
>
>
>
> On 10/13/07, James Bennett <[EMAIL PROTECTED]> wrote:
> >
> >
> > On 10/13/07, Goon <[EMAIL PROTECTED]> wrote:
> > > fair enough, I'm not happy that I can't get {{for x in y[1:5]}}
>
>
> What's the problem. You just send the template 'y':range(1,6). It's very
> simple. I don't think the template system should be changed to do something
> that the programming part of the presentation should do. It makes
> unreadeble, unpractical html code which just gets in the way of practiacal
> web development , it's not mantainance friendly.
>
> Perhaps the documentation will make you happy:
> >
> > http://www.djangoproject.com/documentation/templates/#slice
> >
> > --
> > "Bureaucrat Conrad, you are technically correct -- the best kind of
> > correct."
> >
> > http://www.1km1kt.net/rpg/Marinci.php
> >
> >
> > > >
> >

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: template variables

2007-10-13 Thread Goon



On Oct 13, 3:26 am, "James Bennett" <[EMAIL PROTECTED]> wrote:
> On 10/13/07, Goon <[EMAIL PROTECTED]> wrote:
>
> > fair enough, I'm not happy that I can't get {{for x in y[1:5]}}
>
> Perhaps the documentation will make you happy:


Ok, but let's say I have a template like {{for x in y}}, and I would
like the x's seperated by commas, but I don't want a comma after the
last one?  or better yet cut off after the first 100 characters with a
"..."



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: template variables

2007-10-13 Thread Nikola Stjelja
On 10/13/07, James Bennett <[EMAIL PROTECTED]> wrote:
>
>
> On 10/13/07, Goon <[EMAIL PROTECTED]> wrote:
> > fair enough, I'm not happy that I can't get {{for x in y[1:5]}}


What's the problem. You just send the template 'y':range(1,6). It's very
simple. I don't think the template system should be changed to do something
that the programming part of the presentation should do. It makes
unreadeble, unpractical html code which just gets in the way of practiacal
web development , it's not mantainance friendly.

Perhaps the documentation will make you happy:
>
> http://www.djangoproject.com/documentation/templates/#slice
>
> --
> "Bureaucrat Conrad, you are technically correct -- the best kind of
> correct."
>
> >
>


-- 
Please visit this site and play my RPG!

http://www.1km1kt.net/rpg/Marinci.php

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: template variables

2007-10-13 Thread James Bennett

On 10/13/07, Goon <[EMAIL PROTECTED]> wrote:
> fair enough, I'm not happy that I can't get {{for x in y[1:5]}}

Perhaps the documentation will make you happy:

http://www.djangoproject.com/documentation/templates/#slice

-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: template variables

2007-10-13 Thread Goon

fair enough, I'm not happy that I can't get {{for x in y[1:5]}}

dammit!


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: template variables

2007-10-12 Thread James Bennett

On 10/13/07, Goon <[EMAIL PROTECTED]> wrote:
> can you use variables in django's templates?

Yes.

> and then something like

> {% int x =3; x++ %}

No.

Django's template language is not Python or any other programming
language. Its sole purpose is presentational logic.


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: template variables

2007-10-12 Thread Ramdas S
Simple answer is no. But you can may be try porting mako to to django

On 10/13/07, Goon <[EMAIL PROTECTED]> wrote:
>
>
> can you use variables in django's templates?
>
> so like {% for x in y %}
>
> and then something like
>
> {% int x =3; x++ %}
>
> or something like that, would be mighty helpful
>
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



template variables

2007-10-12 Thread Goon

can you use variables in django's templates?

so like {% for x in y %}

and then something like

{% int x =3; x++ %}

or something like that, would be mighty helpful


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How do I echo template variables?

2007-07-30 Thread Pensee



On Jul 30, 7:42 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> 
> 
> 

try to pprint the variables you pass the template directly in the view
fonction they will appear in the console if you use the django dev
server :)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How do I echo template variables?

2007-07-30 Thread Pensee

Welcome !

On Jul 30, 2:01 pm, "Peter Melvyn" <[EMAIL PROTECTED]> wrote:
> On 7/30/07, Russell Keith-Magee <[EMAIL PROTECTED]> wrote:
>
> > Try {% debug %}
>
> If you mentioned this feature: is there an easy way to reformat {%
> debug %} output the same/similiar way an exception error is reported?

look at the  content of debug pages and copy/paste anything you
find usefull (css, js). You may wrap you debug thing inside a div and
make easier to use with some javascript love :). You may also write
some middleware (?) to include automatically this things in your pages
when debug is on, and release to the community (yeah!)

I don't how complex is your application but most of the time you don't
need to dive into variables that way at least I never did this with my
own application in python/django. Most of the time I use directly
Model Instance or for complex views I prepare some variables in the
view.py file so that it's easier to build (more readable) pages.

Don't forget the python/ipython shell it should be your fellow friend
when writing any python bits because it helps a lot: learn,
experiment, build... more that with any print crap :).


-- Amirouche



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How do I echo template variables?

2007-07-30 Thread Russell Keith-Magee

On 7/30/07, Peter Melvyn <[EMAIL PROTECTED]> wrote:
>
> On 7/30/07, Russell Keith-Magee <[EMAIL PROTECTED]> wrote:
>
> > Try {% debug %}
>
> If you mentioned this feature: is there an easy way to reformat {%
> debug %} output the same/similiar way an exception error is reported?

Not easily. {% debug %} just outputs the context dictionary, without
any particular formatting. The easiest formatting you can use is to
just put {% debug %} in a  block.

The django error pages use a different set of tricks for its
formatting; see django.views.debug for the views that provide those
pages.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How do I echo template variables?

2007-07-30 Thread Peter Melvyn

On 7/30/07, Russell Keith-Magee <[EMAIL PROTECTED]> wrote:

> Try {% debug %}

If you mentioned this feature: is there an easy way to reformat {%
debug %} output the same/similiar way an exception error is reported?

Peter

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How do I echo template variables?

2007-07-30 Thread Chris Hoeppner

Russell Keith-Magee escribió:
> On 7/30/07, Chris Hoeppner <[EMAIL PROTECTED]> wrote:
>   
>> I didn't know of that function. Nice to know. But, is there a var where
>> to access *all* the vars available in the template and it's contents?
>> I've been needing that one for debugging for ever!
>> 
>
> Try {% debug %}
>
> http://www.djangoproject.com/documentation/templates/#debug
>
> Yours
> Russ Magee %-)
>
>   
Gotta give more time to doc-reading. Helpful as always, Russ! Thanks.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How do I echo template variables?

2007-07-30 Thread Russell Keith-Magee

On 7/30/07, Chris Hoeppner <[EMAIL PROTECTED]> wrote:
>
> I didn't know of that function. Nice to know. But, is there a var where
> to access *all* the vars available in the template and it's contents?
> I've been needing that one for debugging for ever!

Try {% debug %}

http://www.djangoproject.com/documentation/templates/#debug

Yours
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How do I echo template variables?

2007-07-30 Thread Chris Hoeppner

Nathan Ostgard escribió:
> Try: {{ data|pprint }}
>
> On Jul 29, 10:42 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>   
>> I'm coming from CakePHP and I would typically set a variable for use
>> in my view with a call to findAll. Since there is a lot of data in the
>> array, I typically do something like:
>>
>> 
>> 
>> 
>>
>> This way, I can find out what data is available in the view and figure
>> out how much I can scale back the recursion.
>>
>> Is there any equivalent in Python/Django? I've searched and didn't
>> come up with anything.
>> 
I didn't know of that function. Nice to know. But, is there a var where 
to access *all* the vars available in the template and it's contents? 
I've been needing that one for debugging for ever!

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How do I echo template variables?

2007-07-30 Thread Nathan Ostgard

Try: {{ data|pprint }}

On Jul 29, 10:42 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> I'm coming from CakePHP and I would typically set a variable for use
> in my view with a call to findAll. Since there is a lot of data in the
> array, I typically do something like:
>
> 
> 
> 
>
> This way, I can find out what data is available in the view and figure
> out how much I can scale back the recursion.
>
> Is there any equivalent in Python/Django? I've searched and didn't
> come up with anything.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



How do I echo template variables?

2007-07-29 Thread [EMAIL PROTECTED]

I'm coming from CakePHP and I would typically set a variable for use
in my view with a call to findAll. Since there is a lot of data in the
array, I typically do something like:





This way, I can find out what data is available in the view and figure
out how much I can scale back the recursion.

Is there any equivalent in Python/Django? I've searched and didn't
come up with anything.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Dynamically generated template variables in admin?

2007-03-20 Thread David Zhou

Hi all,

I'm trying to do something, but before I start, I figure I'll pass it  
on and see if anyone's already done something similar or has a better  
method of accomplishing the same thing.

Let me know if the following sounds feasible or if there's a better  
way of doing it:

Basically, I want to manage my templates in the admin view, and have  
the ability to define custom variables to be filled out.

Then, in say, the "Instance" admin add page, the user is able to  
select a template.  The page will then dymaically generate a table of  
the template variables that need to be filled out along -- like

Title: |==textfield==|
Variable2: |==textfield==|


Live Preview:
|===|
| Preview   |
| of Temp.  |
|===|

I'm thinking that I'll have to edit the admin code somehow, and have  
it parse the selelected template code for {{ variable_title }}.

Then it will use the variable name with underscores replaced with  
spaces as the title.

Should I wait for the new admin code before trying to edit the admin  
interface?

Does this sound like a good way of doing things?

Thanks,

---
David Zhou
[EMAIL PROTECTED]




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Template variables

2006-06-20 Thread Wilson Miner

Hi Patrick,

You might find some helpful responses in this thread:

http://groups.google.com/group/django-users/browse_frm/thread/50ee1c147854769/a79890af3059229d?q=menu&rnum=3#a79890af3059229d

On 6/20/06, Patrick <[EMAIL PROTECTED]> wrote:
>
> Hi i'm newbie and i want to publish my Django website.
> I have this "stupid" problem.
> I have a tab bar like this:
>  
> 
>   
> Home^M
>   
>   
> Blog^M
>   
>   
> Tags^M
>   
>   
> Blank^M
>   
> 
>   
>
> There is a possibility to create a variables so i can set the class
> active when i change the section of my website ?
>
> Or i have to create a simple tag ?
>
> Thx
>
> Patrick
>
>
>
> --
> __
> email:[EMAIL PROTECTED]
> http://patrick.pupazzo.org
> __
>
>
>
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Template variables

2006-06-20 Thread Patrick

Hi i'm newbie and i want to publish my Django website.
I have this "stupid" problem.
I have a tab bar like this:
 

  
Home^M
  
  
Blog^M
  
  
Tags^M
  
  
Blank^M
  

  

There is a possibility to create a variables so i can set the class 
active when i change the section of my website ?

Or i have to create a simple tag ?

Thx

Patrick



-- 
__
email:[EMAIL PROTECTED]
http://patrick.pupazzo.org
__




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: template variables and looping with attributes

2006-01-22 Thread akaihola

You could define a filter "lookup":

from django.core.template import resolve_variable, Library
register = Library()
def lookup(value, arg):
return resolve_variable(arg, value)
register.filter(lookup)

and use it in your code like this:


{%for r in object_list %}

{%for c in field_list %}
 {{r|lookup:c}}
{%endfor%}

{%endfor%}




template variables and looping with attributes

2006-01-21 Thread The Boss

i am trying to make a table template  similar to what i find for inline
editable modules in the admin interface.
I want to send a list of (same class) objects and fields of those
objects and then get a row for each object with a col for each desired
field.  I thought this would be easy because it seemed like the obvious
way to do this is:


{%for r in object_list %}

{%for c in field_list %}
 {{r.c}}
{%endfor%}

{%endfor%}


however it seems that although you can put loop variables before the
dot, you have to have fixed text after the dot.  i.e.  r.id will give a
table of object id's but r.c generates nothing.

This seems sort of surprizing so I am wondering if either I am doing
something wrong or there is a way around this?   It really doesn't make
any sense to me that this doesn't work



Re: Passing template tags template variables

2006-01-14 Thread Alice

excellent - thanks. (it is very easy) ...


Alice



Re: Passing template tags template variables

2006-01-14 Thread Luke Plant

On Sat, 14 Jan 2006 16:12:50 - Alice wrote:

> I just finished writing the tag and realized that it won't work unless
> I can access the data passed to the template. Any help in getting
> around this (probably simple) problem would be welcome.

The 'render' method of custom tag gets passed the 'context' of the
template:

class YouCustomTagNode:
def render(self, context):
...

That context is the same one passed into the template for rendering. If
the custom tag always uses the same data from the context, this is the
way to go, and is very easy.

Luke

-- 
"He knows the way I take: when he has tried me, I shall come forth as 
gold" (Job 23:10).

Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/


Re: Passing template tags template variables

2006-01-14 Thread Maniac


Alice wrote:


Is there a means to pass a template variable {{ user_id }} to a custom
template tag,
{% build_menu "user_id" %} ?
 

In fact you can treat anything after your tag name as you like, it's 
just a string. But for such natural thing as treating it as a variable 
Django will help. For this you have to omit quotes and then in your 
template tag function do:


def do_build_menu(parser, token):
 bits = token.contents.split()
 return BuildMenuNode(parser.compile_filter(bits[0]))

compile_filter is needed to store the first parameter to later evaluate 
it when actual context will be available:


class BuildMenuNode:
 def __ini__(self, user_id_var):
   self.user_id_var=user_id_var

 def render(self,context):
   user_id=self.user_id_var.resolve(context)
   ...


Passing template tags template variables

2006-01-14 Thread Alice

Is there a means to pass a template variable {{ user_id }} to a custom
template tag,
{% build_menu "user_id" %} ?

I just finished writing the tag and realized that it won't work unless
I can access the data passed to the template. Any help in getting
around this (probably simple) problem would be welcome.


Alice