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}) > > <snip>
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-context-requestcontext (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.