Re: Messages framework is not showing messages in my templates

2011-02-19 Thread Gabriel Prat
Thanks Daniel, is just this, I forgget the context_processor on my
return... thanks for all.

G.


On 18 Feb, 19:38, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Friday, February 18, 2011 10:56:54 AM UTC, Gabriel Prat wrote:
>
> > Hi all, I'm trying to use messages framework, I've checked that
> > middleware, context processor and app is well configured (I'm running
> > django development version which a standard manage.py startproject
> > includes all needed stuff)
>
> > So, let me write a little bit of code, assume a model like:
>
> > class MyModel(models.Model):
> >     name            = models.TextField(max_length = 100)
> >     url             = models.URLField()
>
> > And a simple form:
>
> > class mymodelForm(forms.ModelForm):
> >     name = forms.CharField()
> >     url = forms.URLField()
> >     class Meta:
> >         model = MyModel
>
> > A basic view (assuming all needed imports in top of my views.py file):
>
> > def mymodel_create(request):
> >     from forms import mymodelForm
> >     if request.method == 'POST':
> >         form = mymodelForm(request.POST)
> >         if form.is_valid():
> >             form.save()
> >             messages.success(request, _('Model has been saved'))
> >     else:
> >         form = projectForm()
>
> >     return render_to_response('mymodel_create.html', {'form' : form})
>
> > 
>
> The context processor is not invoked, because you're not using a
> RequestContext. So the messages variable is not added to your context. The
> last line should be:
>
>     return render_to_response('mymodel_create.html', {'form' : form},
> context_instance=RequestContext)
>
> See the documentation:
>  http://docs.djangoproject.com/en/1.2/ref/templates/api/#subclassing-c...
> (the Note box, a couple of screens down - unfortunately there's no handy id
> to link to directly)
> --
> 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.



Messages framework is not showing messages in my templates

2011-02-18 Thread Gabriel Prat
Hi all, I'm trying to use messages framework, I've checked that
middleware, context processor and app is well configured (I'm running
django development version which a standard manage.py startproject
includes all needed stuff)

So, let me write a little bit of code, assume a model like:

class MyModel(models.Model):
name= models.TextField(max_length = 100)
url = models.URLField()

And a simple form:

class mymodelForm(forms.ModelForm):
name = forms.CharField()
url = forms.URLField()
class Meta:
model = MyModel

A basic view (assuming all needed imports in top of my views.py file):

def mymodel_create(request):
from forms import mymodelForm
if request.method == 'POST':
form = mymodelForm(request.POST)
if form.is_valid():
form.save()
messages.success(request, _('Model has been saved'))
else:
form = projectForm()

return render_to_response('mymodel_create.html', {'form' : form})

and my template (basic as well)

{% if messages %}

{% for message in messages %}
{{ message }}
{% endfor %}

{% else %}
No messages to show
{% endif %}

{% csrf_token %}

{{ form.as_ul }}

Save



I load it, fill my form up in my browser, submit it and it saves my
model correctly but don't shows any messages, always goes to {% else
%} template part.

So, If I change my URL to /admin the login (or dashboard if logged in)
is showed and my messages appears there!

Someone can help me to fix this problem? I've been searching over
Django docs and Google with no helping topic.

Thanks in advance,

Gabriel

-- 
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.