Should redirect work from my Application Content's view?

131 views
Skip to first unread message

Colin Kahn

unread,
Jan 14, 2013, 3:19:35 PM1/14/13
to django-...@googlegroups.com
I tried looking for anyone else having this problem and couldn't find anything so I just wanted to rule out whether I was doing something wrong. 

I'm trying to integrate a django app as Application Content, and some of the views in it return `redirect('view_name')` which is giving me a `NoReverseMatch at /url/` error. If I manually type in the url it's trying to find it works. 

So, I'm wondering if FeinCMS Application Content just doesn't work with redirect or if there's something i'm missing. 

Matthias Kestenholz

unread,
Jan 19, 2013, 9:21:48 AM1/19/13
to FeinCMS
Hi Colin

Unfortunately, URLconfs and views included through ApplicationContent are not reversible using django.core.urlresolvers.reverse. You have to use feincms.content.application.models.app_reverse for those entries, for example:

app_reverse('view_name', 'yourapp.urls')

So, instead of using django.shortcuts.redirect you'll have to use HttpResponseRedirect and app_reverse.
Please get back to me/us if you have any additional questions about reversing URLs.


Thanks,
Matthias

M M Rahman

unread,
Feb 20, 2013, 7:45:29 AM2/20/13
to django-...@googlegroups.com
Hi Matthias, 

Hope you can solve my riddle :)

I have a form and on submit I should land on a '/thanks/' page. 

The code looks like:
class FranchiseFormContent(models.Model):

    class Meta:
        abstract = True

    def render(self, **kwargs):
        form = FranchiseForm
        request = kwargs.get('request')
        if request.method == 'POST':
            form = FranchiseForm(request.POST)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect('/thanks/')
            else:
                form = FranchiseForm(request.POST)

        return render_to_string('franchise_form.html', {'form': form}, context_instance=RequestContext(request))

But actually after submitting the form it does not redirect the page the '/thanks' page, instead it shows the following on the region:

Content-Type: text/html; charset=utf-8 Location: /thanks/

So my question is from a feincms content block how can we redirect to a new page after from submission?

Kind Regards,
M M Rahman 

Matthias Kestenholz

unread,
Feb 20, 2013, 8:00:20 AM2/20/13
to FeinCMS
Hi,


On Wed, Feb 20, 2013 at 1:45 PM, M M Rahman <mmr...@gmail.com> wrote:
Hi Matthias, 

Hope you can solve my riddle :)

I have a form and on submit I should land on a '/thanks/' page. 


There is a small but important difference between render() and process(): Only the latter may return HTTP response instances.

I'd do it like this (untested):


class FranchiseFormContent(models.Model):
    class Meta:
        abstract = True
       
    def process(self, request, **kwargs):
        if request.method == 'POST':
            self.form = FranchiseForm(request.POST)
            if self.form.is_valid():
                self.form.save()
                return HttpResponseRedirect('thanks/')
        else:
            self.form = FranchiseForm()
           
    def render(self, **kwargs):
        return render_to_string('franchise_form.html', {
            'content': self,
            'form': self.form,
            }, context_instance=kwargs.get('context'))
 


HTH,
Matthias

M M Rahman

unread,
Feb 20, 2013, 9:27:58 AM2/20/13
to django-...@googlegroups.com
Hi Matthias,

This is exactly I was looking for.
This is my first week with Feincms, didn't know about 'process' method at all.

Working like a charm.

M M Rahman

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



--
Muhammad Mostafizur Rahman
Software Developer
London, UK

M M Rahman

unread,
Feb 21, 2013, 4:23:50 AM2/21/13
to django-...@googlegroups.com
Hi Matthias, 

I know its out of the topic. But need some assistance understanding the Feincms admin forms. 

I am creating a content from my model using foreign key but I want the object displayed as checkbox or multi select instead of a combo.

Some one told me to use
feincms_item_editor_form 
But I am quite unsure how to use it.

My model is :
class TeamMember(models.Model):
    name = models.CharField(max_length=200)
    position = models.CharField(max_length=64)
    image = models.ImageField(upload_to='profile')
    description = models.TextField()
    def __unicode__(self):
        return "%s " % self.name

And my content is:
class TeamMemberContent(models.Model):
    member = models.ForeignKey(TeamMember)

    class Meta:
        abstract = True
    def render(self, **kwargs):

        request = kwargs.get('request')
        print request
        return render_to_string('team_member.html', {'members': self.member})

Thank you very much in advance
Reply all
Reply to author
Forward
0 new messages